本文整理汇总了C++中TopoDS_Shape类的典型用法代码示例。如果您正苦于以下问题:C++ TopoDS_Shape类的具体用法?C++ TopoDS_Shape怎么用?C++ TopoDS_Shape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TopoDS_Shape类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: getValue
bool IfcGeom::Kernel::convert(const IfcSchema::IfcExtrudedAreaSolid* l, TopoDS_Shape& shape) {
const double height = l->Depth() * getValue(GV_LENGTH_UNIT);
if (height < getValue(GV_PRECISION)) {
Logger::Message(Logger::LOG_ERROR, "Non-positive extrusion height encountered for:", l->entity);
return false;
}
TopoDS_Shape face;
if ( !convert_face(l->SweptArea(),face) ) return false;
gp_Trsf trsf;
IfcGeom::Kernel::convert(l->Position(),trsf);
gp_Dir dir;
convert(l->ExtrudedDirection(),dir);
shape.Nullify();
if (face.ShapeType() == TopAbs_COMPOUND) {
// For compounds (most likely the result of a IfcCompositeProfileDef)
// create a compound solid shape.
TopExp_Explorer exp(face, TopAbs_FACE);
TopoDS_CompSolid compound;
BRep_Builder builder;
builder.MakeCompSolid(compound);
int num_faces_extruded = 0;
for (; exp.More(); exp.Next(), ++num_faces_extruded) {
builder.Add(compound, BRepPrimAPI_MakePrism(exp.Current(), height*dir));
}
if (num_faces_extruded) {
shape = compound;
}
}
if (shape.IsNull()) {
shape = BRepPrimAPI_MakePrism(face, height*dir);
}
shape.Move(trsf);
return ! shape.IsNull();
}
开发者ID:ISBE-TUe,项目名称:IfcOpenShell-HDF5,代码行数:47,代码来源:IfcGeomShapes.cpp
示例2: It
//=======================================================================
//function : CompsolidToCompound
//purpose :
//=======================================================================
TopoDS_Shape GEOMUtils::CompsolidToCompound (const TopoDS_Shape& theCompsolid)
{
if (theCompsolid.ShapeType() != TopAbs_COMPSOLID) {
return theCompsolid;
}
TopoDS_Compound aCompound;
BRep_Builder B;
B.MakeCompound(aCompound);
TopTools_MapOfShape mapShape;
TopoDS_Iterator It (theCompsolid, Standard_True, Standard_True);
for (; It.More(); It.Next()) {
TopoDS_Shape aShape_i = It.Value();
if (mapShape.Add(aShape_i)) {
B.Add(aCompound, aShape_i);
}
}
return aCompound;
}
开发者ID:AjinkyaDahale,项目名称:FreeCAD,代码行数:26,代码来源:GEOMUtils.cpp
示例3: GetVolumeProperties
bool ChCascadeDoc::GetVolumeProperties(const TopoDS_Shape& mshape, ///< pass the shape here
const double density, ///< pass the density here
ChVector<>& center_position, ///< get the position center, respect to shape pos.
ChVector<>& inertiaXX, ///< get the inertia diagonal terms
ChVector<>& inertiaXY, ///< get the inertia extradiagonal terms
double& volume, ///< get the volume
double& mass ///< get the mass
)
{
if (mshape.IsNull())
return false;
GProp_GProps mprops;
GProp_GProps vprops;
BRepGProp::VolumeProperties(mshape,mprops);
BRepGProp::VolumeProperties(mshape,vprops);
mprops.Add(mprops, density);
mass = mprops.Mass();
volume = vprops.Mass();
gp_Pnt G = mprops.CentreOfMass ();
gp_Mat I = mprops.MatrixOfInertia();
center_position.x = G.X();
center_position.y = G.Y();
center_position.z = G.Z();
inertiaXX.x = I(1,1);
inertiaXX.y = I(2,2);
inertiaXX.z = I(3,3);
inertiaXY.x = I(1,2);
inertiaXY.y = I(1,3);
inertiaXY.z = I(2,3);
return true;
}
开发者ID:saggita,项目名称:chrono,代码行数:37,代码来源:ChCascadeDoc.cpp
示例4: ForShape
virtual bool ForShape(TopoDS_Shape& mshape, TopLoc_Location& mloc, char* mname, int mlevel, TDF_Label& mlabel) {
if (this->level_names.size() > mlevel) {
if (wildcard_compare(level_names[mlevel].c_str(), mname)) {
if (level_copy[mlevel] != -2) {
level_copy[mlevel] = level_copy[mlevel] - 1;
if (level_copy[mlevel] < -1)
level_copy[mlevel] = -1;
}
if ((level_copy[mlevel] == 0) || (level_copy[mlevel] == -2)) {
if (mlevel == this->level_names.size() - 1) {
// Found!!!
if (this->set_location_to_root)
mshape.Location(mloc);
// For single istance: only 1st found shape is considered
if (!res_found) {
res_found = true;
res_shape = mshape;
res_loc = mloc;
res_level = mlevel;
res_label = mlabel;
}
// Add to the shape compound, for multiple results
aBuilder.Add(res_comp, mshape);
}
return true; // proceed!
}
return false; // break, matching name but not #ID, not needed to go deeper in levels
}
return false; // break, not matching, not needed to go deeper in levels
} else
return false; // break, not needed to go deeper in levels than in string wildcard
}
开发者ID:armanpazouki,项目名称:chrono,代码行数:36,代码来源:ChCascadeDoc.cpp
示例5: Handle
Standard_Boolean GEOMImpl_HealingDriver::SuppressFaces (GEOMImpl_IHealing* theHI,
const TopoDS_Shape& theOriginalShape,
TopoDS_Shape& theOutShape) const
{
Handle(TColStd_HArray1OfInteger) aFaces = theHI->GetFaces();
Standard_Boolean aResult = Standard_False;
if (aFaces.IsNull()) {
ShHealOper_RemoveFace aHealer (theOriginalShape);
aResult = aHealer.Perform();
if (aResult)
theOutShape = aHealer.GetResultShape();
else
raiseNotDoneExeption(aHealer.GetErrorStatus());
}
else {
TopTools_SequenceOfShape aShapesFaces;
TopTools_IndexedMapOfShape aShapes;
TopExp::MapShapes(theOriginalShape, aShapes);
for (int i = 1; i <= aFaces->Length(); i++) {
int indexOfFace = aFaces->Value(i);
TopoDS_Shape aFace = aShapes.FindKey(indexOfFace);
aShapesFaces.Append(aFace);
}
SuppressFacesRec(aShapesFaces, theOriginalShape, theOutShape);
if ((theOriginalShape.ShapeType() == TopAbs_COMPOUND ||
theOriginalShape.ShapeType() == TopAbs_COMPSOLID)) {
TopoDS_Shape aSh = theOutShape;
theOutShape = GEOMImpl_GlueDriver::GlueFaces(aSh, Precision::Confusion(), Standard_True);
}
}
return Standard_True;
}
开发者ID:dbarbier,项目名称:pythonocc,代码行数:36,代码来源:GEOMImpl_HealingDriver.cpp
示例6: selectionName
QString SetupResultBase::selectionName(ResultEntry *entry, const TopoDS_Shape &shape)
{
ResultEntry *parentEntry = entry;
while(parentEntry->name.isEmpty())
parentEntry = parentEntry->parent;
QString stringOut;
QTextStream stream(&stringOut);
stream << parentEntry->name;
stream << '.';
TopTools_IndexedMapOfShape shapeMap;
int index(-1);
switch (shape.ShapeType())
{
case TopAbs_FACE:
TopExp::MapShapes(parentEntry->shape, TopAbs_FACE, shapeMap);
stream << "Face";
break;
case TopAbs_EDGE:
TopExp::MapShapes(parentEntry->shape, TopAbs_EDGE, shapeMap);
stream << "Edge";
break;
case TopAbs_VERTEX:
TopExp::MapShapes(parentEntry->shape, TopAbs_VERTEX, shapeMap);
stream << "Vertex";
break;
default:
stream << "Unexpected shape type";
break;
}
index = shapeMap.FindIndex(shape);
stream << index;
return stringOut;
}
开发者ID:MarcusWolschon,项目名称:FreeCAD_sf_master,代码行数:36,代码来源:TaskCheckGeometry.cpp
示例7: if
App::DocumentObjectExecReturn *Sweep::execute(void)
{
if (Sections.getSize() == 0)
return new App::DocumentObjectExecReturn("No sections linked.");
App::DocumentObject* spine = Spine.getValue();
if (!(spine && spine->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())))
return new App::DocumentObjectExecReturn("No spine linked.");
const std::vector<std::string>& subedge = Spine.getSubValues();
TopoDS_Shape path;
const Part::TopoShape& shape = static_cast<Part::Feature*>(spine)->Shape.getValue();
if (!shape._Shape.IsNull()) {
try {
if (!subedge.empty()) {
BRepBuilderAPI_MakeWire mkWire;
for (std::vector<std::string>::const_iterator it = subedge.begin(); it != subedge.end(); ++it) {
TopoDS_Shape subshape = shape.getSubShape(it->c_str());
mkWire.Add(TopoDS::Edge(subshape));
}
path = mkWire.Wire();
}
else if (shape._Shape.ShapeType() == TopAbs_EDGE) {
path = shape._Shape;
}
else if (shape._Shape.ShapeType() == TopAbs_WIRE) {
BRepBuilderAPI_MakeWire mkWire(TopoDS::Wire(shape._Shape));
path = mkWire.Wire();
}
else if (shape._Shape.ShapeType() == TopAbs_COMPOUND) {
TopoDS_Iterator it(shape._Shape);
for (; it.More(); it.Next()) {
if (it.Value().IsNull())
return new App::DocumentObjectExecReturn("In valid element in spine.");
if ((it.Value().ShapeType() != TopAbs_EDGE) &&
(it.Value().ShapeType() != TopAbs_WIRE)) {
return new App::DocumentObjectExecReturn("Element in spine is neither an edge nor a wire.");
}
}
Handle(TopTools_HSequenceOfShape) hEdges = new TopTools_HSequenceOfShape();
Handle(TopTools_HSequenceOfShape) hWires = new TopTools_HSequenceOfShape();
for (TopExp_Explorer xp(shape._Shape, TopAbs_EDGE); xp.More(); xp.Next())
hEdges->Append(xp.Current());
ShapeAnalysis_FreeBounds::ConnectEdgesToWires(hEdges, Precision::Confusion(), Standard_True, hWires);
int len = hWires->Length();
if (len != 1)
return new App::DocumentObjectExecReturn("Spine is not connected.");
path = hWires->Value(1);
}
else {
return new App::DocumentObjectExecReturn("Spine is neither an edge nor a wire.");
}
}
catch (Standard_Failure) {
return new App::DocumentObjectExecReturn("Invalid spine.");
}
}
try {
TopTools_ListOfShape profiles;
const std::vector<App::DocumentObject*>& shapes = Sections.getValues();
std::vector<App::DocumentObject*>::const_iterator it;
for (it = shapes.begin(); it != shapes.end(); ++it) {
if (!(*it)->isDerivedFrom(Part::Feature::getClassTypeId()))
return new App::DocumentObjectExecReturn("Linked object is not a shape.");
TopoDS_Shape shape = static_cast<Part::Feature*>(*it)->Shape.getValue();
if (shape.IsNull())
return new App::DocumentObjectExecReturn("Linked shape is invalid.");
// Extract first element of a compound
if (shape.ShapeType() == TopAbs_COMPOUND) {
TopoDS_Iterator it(shape);
for (; it.More(); it.Next()) {
if (!it.Value().IsNull()) {
shape = it.Value();
break;
}
}
}
// There is a weird behaviour of BRepOffsetAPI_MakePipeShell when trying to add the wire as is.
// If we re-create the wire then everything works fine.
// http://forum.freecadweb.org/viewtopic.php?f=10&t=2673&sid=fbcd2ff4589f0b2f79ed899b0b990648#p20268
if (shape.ShapeType() == TopAbs_FACE) {
TopoDS_Wire faceouterWire = ShapeAnalysis::OuterWire(TopoDS::Face(shape));
profiles.Append(faceouterWire);
}
else if (shape.ShapeType() == TopAbs_WIRE) {
BRepBuilderAPI_MakeWire mkWire(TopoDS::Wire(shape));
profiles.Append(mkWire.Wire());
}
else if (shape.ShapeType() == TopAbs_EDGE) {
BRepBuilderAPI_MakeWire mkWire(TopoDS::Edge(shape));
profiles.Append(mkWire.Wire());
}
else if (shape.ShapeType() == TopAbs_VERTEX) {
profiles.Append(shape);
}
else {
return new App::DocumentObjectExecReturn("Linked shape is not a vertex, edge, wire nor face.");
//.........这里部分代码省略.........
开发者ID:PrLayton,项目名称:SeriousFractal,代码行数:101,代码来源:PartFeatures.cpp
示例8: copy
App::DocumentObjectExecReturn *Revolution::execute(void)
{
App::DocumentObject* link = Sketch.getValue();
if (!link)
return new App::DocumentObjectExecReturn("No sketch linked");
if (!link->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId()))
return new App::DocumentObjectExecReturn("Linked object is not a Sketch or Part2DObject");
Part::Part2DObject* pcSketch=static_cast<Part::Part2DObject*>(link);
TopoDS_Shape shape = pcSketch->Shape.getShape()._Shape;
if (shape.IsNull())
return new App::DocumentObjectExecReturn("Linked shape object is empty");
// this is a workaround for an obscure OCC bug which leads to empty tessellations
// for some faces. Making an explicit copy of the linked shape seems to fix it.
// The error only happens when re-computing the shape.
if (!this->Shape.getValue().IsNull()) {
BRepBuilderAPI_Copy copy(shape);
shape = copy.Shape();
if (shape.IsNull())
return new App::DocumentObjectExecReturn("Linked shape object is empty");
}
TopExp_Explorer ex;
std::vector<TopoDS_Wire> wires;
for (ex.Init(shape, TopAbs_WIRE); ex.More(); ex.Next()) {
wires.push_back(TopoDS::Wire(ex.Current()));
}
if (wires.empty()) // there can be several wires
return new App::DocumentObjectExecReturn("Linked shape object is not a wire");
// get the Sketch plane
Base::Placement SketchPlm = pcSketch->Placement.getValue();
// get reference axis
App::DocumentObject *pcReferenceAxis = ReferenceAxis.getValue();
const std::vector<std::string> &subReferenceAxis = ReferenceAxis.getSubValues();
if (pcReferenceAxis && pcReferenceAxis == pcSketch) {
bool hasValidAxis=false;
Base::Axis axis;
if (subReferenceAxis[0] == "V_Axis") {
hasValidAxis = true;
axis = pcSketch->getAxis(Part::Part2DObject::V_Axis);
}
else if (subReferenceAxis[0] == "H_Axis") {
hasValidAxis = true;
axis = pcSketch->getAxis(Part::Part2DObject::H_Axis);
}
else if (subReferenceAxis[0].size() > 4 && subReferenceAxis[0].substr(0,4) == "Axis") {
int AxId = std::atoi(subReferenceAxis[0].substr(4,4000).c_str());
if (AxId >= 0 && AxId < pcSketch->getAxisCount()) {
hasValidAxis = true;
axis = pcSketch->getAxis(AxId);
}
}
if (hasValidAxis) {
axis *= SketchPlm;
Base::Vector3d base=axis.getBase();
Base::Vector3d dir=axis.getDirection();
Base.setValue(base.x,base.y,base.z);
Axis.setValue(dir.x,dir.y,dir.z);
}
}
// get revolve axis
Base::Vector3f b = Base.getValue();
gp_Pnt pnt(b.x,b.y,b.z);
Base::Vector3f v = Axis.getValue();
gp_Dir dir(v.x,v.y,v.z);
// get the support of the Sketch if any
App::DocumentObject* pcSupport = pcSketch->Support.getValue();
Part::Feature *SupportObject = 0;
if (pcSupport && pcSupport->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
SupportObject = static_cast<Part::Feature*>(pcSupport);
TopoDS_Shape aFace = makeFace(wires);
if (aFace.IsNull())
return new App::DocumentObjectExecReturn("Creating a face from sketch failed");
// Rotate the face by half the angle to get revolution symmetric to sketch plane
if (Midplane.getValue()) {
gp_Trsf mov;
mov.SetRotation(gp_Ax1(pnt, dir), Base::toRadians<double>(Angle.getValue()) * (-1.0) / 2.0);
TopLoc_Location loc(mov);
aFace.Move(loc);
}
this->positionBySketch();
TopLoc_Location invObjLoc = this->getLocation().Inverted();
pnt.Transform(invObjLoc.Transformation());
dir.Transform(invObjLoc.Transformation());
// Reverse angle if selected
double angle = Base::toRadians<double>(Angle.getValue());
if (Reversed.getValue() && !Midplane.getValue())
angle *= (-1.0);
try {
//.........这里部分代码省略.........
开发者ID:emagdalena,项目名称:FreeCAD,代码行数:101,代码来源:FeatureRevolution.cpp
示例9: gp_Dir
const std::list<gp_Trsf> LinearPattern::getTransformations(const std::vector<App::DocumentObject*>)
{
std::string stdDirection = StdDirection.getValue();
float distance = Length.getValue();
if (distance < Precision::Confusion())
throw Base::Exception("Pattern length too small");
int occurrences = Occurrences.getValue();
if (occurrences < 2)
throw Base::Exception("At least two occurrences required");
bool reversed = Reversed.getValue();
gp_Dir dir;
double offset = distance / (occurrences - 1);
if (!stdDirection.empty()) {
// Note: The placement code commented out below had the defect of working always on the
// absolute X,Y,Z direction, not on the relative coordinate system of the Body feature.
// It requires positionBySupport() to be called in Transformed::Execute() AFTER
// the call to getTransformations()
// New code thanks to logari81
if (stdDirection == "X") {
//dir = Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(1,0,0));
dir = gp_Dir(1,0,0);
} else if (stdDirection == "Y") {
//dir = Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(0,1,0));
dir = gp_Dir(0,1,0);
} else if(stdDirection == "Z") {
//dir = Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(0,0,1));
dir = gp_Dir(0,0,1);
} else {
throw Base::Exception("Invalid direction (must be X, Y or Z)");
}
} else {
App::DocumentObject* refObject = Direction.getValue();
if (refObject == NULL)
throw Base::Exception("No direction specified");
if (!refObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
throw Base::Exception("Direction reference must be edge or face of a feature");
std::vector<std::string> subStrings = Direction.getSubValues();
if (subStrings.empty() || subStrings[0].empty())
throw Base::Exception("No direction reference specified");
Part::Feature* refFeature = static_cast<Part::Feature*>(refObject);
Part::TopoShape refShape = refFeature->Shape.getShape();
TopoDS_Shape ref = refShape.getSubShape(subStrings[0].c_str());
if (ref.ShapeType() == TopAbs_FACE) {
TopoDS_Face refFace = TopoDS::Face(ref);
if (refFace.IsNull())
throw Base::Exception("Failed to extract direction plane");
BRepAdaptor_Surface adapt(refFace);
if (adapt.GetType() != GeomAbs_Plane)
throw Base::Exception("Direction face must be planar");
dir = adapt.Plane().Axis().Direction();
//gp_Dir d = adapt.Plane().Axis().Direction();
//dir = Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(d.X(), d.Y(), d.Z()));
} else if (ref.ShapeType() == TopAbs_EDGE) {
TopoDS_Edge refEdge = TopoDS::Edge(ref);
if (refEdge.IsNull())
throw Base::Exception("Failed to extract direction edge");
BRepAdaptor_Curve adapt(refEdge);
if (adapt.GetType() != GeomAbs_Line)
throw Base::Exception("Direction edge must be a straight line");
//gp_Dir d = adapt.Line().Direction();
//dir = Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(d.X(), d.Y(), d.Z()));
dir = adapt.Line().Direction();
} else {
throw Base::Exception("Direction reference must be edge or face");
}
TopLoc_Location invObjLoc = this->getLocation().Inverted();
dir.Transform(invObjLoc.Transformation());
}
// get the support placement
// TODO: Check for NULL pointer
/*Part::Feature* supportFeature = static_cast<Part::Feature*>(originals.front());
if (supportFeature == NULL)
throw Base::Exception("Cannot work on invalid support shape");
Base::Placement supportPlacement = supportFeature->Placement.getValue();
dir *= supportPlacement;
gp_Vec direction(dir.getDirection().x, dir.getDirection().y, dir.getDirection().z);*/
gp_Vec direction(dir.X(), dir.Y(), dir.Z());
if (reversed)
direction.Reverse();
// Note: The original feature is NOT included in the list of transformations! Therefore
// we start with occurrence number 1, not number 0
std::list<gp_Trsf> transformations;
gp_Trsf trans;
transformations.push_back(trans); // identity transformation
for (int i = 1; i < occurrences; i++) {
trans.SetTranslation(direction * i * offset);
transformations.push_back(trans);
}
return transformations;
//.........这里部分代码省略.........
开发者ID:Daedalus12,项目名称:FreeCAD_sf_master,代码行数:101,代码来源:FeatureLinearPattern.cpp
示例10: it
App::DocumentObjectExecReturn *MultiFuse::execute(void)
{
std::vector<TopoDS_Shape> s;
std::vector<App::DocumentObject*> obj = Shapes.getValues();
std::vector<App::DocumentObject*>::iterator it;
for (it = obj.begin(); it != obj.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
s.push_back(static_cast<Part::Feature*>(*it)->Shape.getValue());
}
}
bool argumentsAreInCompound = false;
TopoDS_Shape compoundOfArguments;
//if only one source shape, and it is a compound - fuse children of the compound
if (s.size() == 1){
compoundOfArguments = s[0];
if (compoundOfArguments.ShapeType() == TopAbs_COMPOUND){
s.clear();
TopoDS_Iterator it(compoundOfArguments);
for (; it.More(); it.Next()) {
const TopoDS_Shape& aChild = it.Value();
s.push_back(aChild);
}
argumentsAreInCompound = true;
}
}
if (s.size() >= 2) {
try {
std::vector<ShapeHistory> history;
#if OCC_VERSION_HEX <= 0x060800
TopoDS_Shape resShape = s.front();
if (resShape.IsNull())
throw Base::Exception("Input shape is null");
for (std::vector<TopoDS_Shape>::iterator it = s.begin()+1; it != s.end(); ++it) {
if (it->IsNull())
throw Base::Exception("Input shape is null");
// Let's call algorithm computing a fuse operation:
BRepAlgoAPI_Fuse mkFuse(resShape, *it);
// Let's check if the fusion has been successful
if (!mkFuse.IsDone())
throw Base::Exception("Fusion failed");
resShape = mkFuse.Shape();
ShapeHistory hist1 = buildHistory(mkFuse, TopAbs_FACE, resShape, mkFuse.Shape1());
ShapeHistory hist2 = buildHistory(mkFuse, TopAbs_FACE, resShape, mkFuse.Shape2());
if (history.empty()) {
history.push_back(hist1);
history.push_back(hist2);
}
else {
for (std::vector<ShapeHistory>::iterator jt = history.begin(); jt != history.end(); ++jt)
*jt = joinHistory(*jt, hist1);
history.push_back(hist2);
}
}
#else
BRepAlgoAPI_Fuse mkFuse;
TopTools_ListOfShape shapeArguments,shapeTools;
shapeArguments.Append(s.front());
for (std::vector<TopoDS_Shape>::iterator it = s.begin()+1; it != s.end(); ++it) {
if (it->IsNull())
throw Base::Exception("Input shape is null");
shapeTools.Append(*it);
}
mkFuse.SetArguments(shapeArguments);
mkFuse.SetTools(shapeTools);
mkFuse.Build();
if (!mkFuse.IsDone())
throw Base::Exception("MultiFusion failed");
TopoDS_Shape resShape = mkFuse.Shape();
for (std::vector<TopoDS_Shape>::iterator it = s.begin(); it != s.end(); ++it) {
history.push_back(buildHistory(mkFuse, TopAbs_FACE, resShape, *it));
}
#endif
if (resShape.IsNull())
throw Base::Exception("Resulting shape is null");
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part/Boolean");
if (hGrp->GetBool("CheckModel", false)) {
BRepCheck_Analyzer aChecker(resShape);
if (! aChecker.IsValid() ) {
return new App::DocumentObjectExecReturn("Resulting shape is invalid");
}
}
if (hGrp->GetBool("RefineModel", false)) {
try {
TopoDS_Shape oldShape = resShape;
BRepBuilderAPI_RefineModel mkRefine(oldShape);
resShape = mkRefine.Shape();
ShapeHistory hist = buildHistory(mkRefine, TopAbs_FACE, resShape, oldShape);
for (std::vector<ShapeHistory>::iterator jt = history.begin(); jt != history.end(); ++jt)
*jt = joinHistory(*jt, hist);
}
catch (Standard_Failure) {
// do nothing
//.........这里部分代码省略.........
开发者ID:itain,项目名称:FreeCAD,代码行数:101,代码来源:FeaturePartFuse.cpp
示例11: getTransformations
App::DocumentObjectExecReturn *Transformed::execute(void)
{
rejected.clear();
std::vector<App::DocumentObject*> originals = Originals.getValues();
if (originals.empty()) // typically InsideMultiTransform
return App::DocumentObject::StdReturn;
this->positionBySupport();
// get transformations from subclass by calling virtual method
std::list<gp_Trsf> transformations;
try {
transformations = getTransformations(originals);
} catch (Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
if (transformations.empty())
return App::DocumentObject::StdReturn; // No transformations defined, exit silently
// Get the support
// NOTE: Because of the way we define the support, FeatureTransformed can only work on
// one Body feature at a time
// TODO: Currently, the support is simply the first Original. Change this to the Body feature later
Part::Feature* supportFeature = static_cast<Part::Feature*>(getSupportObject());
const Part::TopoShape& supportTopShape = supportFeature->Shape.getShape();
if (supportTopShape._Shape.IsNull())
return new App::DocumentObjectExecReturn("Cannot transform invalid support shape");
// create an untransformed copy of the support shape
Part::TopoShape supportShape(supportTopShape);
supportShape.setTransform(Base::Matrix4D());
TopoDS_Shape support = supportShape._Shape;
// NOTE: It would be possible to build a compound from all original addShapes/subShapes and then
// transform the compounds as a whole. But we choose to apply the transformations to each
// Original separately. This way it is easier to discover what feature causes a fuse/cut
// to fail. The downside is that performance suffers when there are many originals. But it seems
// safe to assume that in most cases there are few originals and many transformations
for (std::vector<App::DocumentObject*>::const_iterator o = originals.begin(); o != originals.end(); o++)
{
TopoDS_Shape shape;
bool fuse;
if ((*o)->getTypeId().isDerivedFrom(PartDesign::Additive::getClassTypeId())) {
PartDesign::Additive* addFeature = static_cast<PartDesign::Additive*>(*o);
shape = addFeature->AddShape.getShape()._Shape;
if (shape.IsNull())
return new App::DocumentObjectExecReturn("Shape of additive feature is empty");
fuse = true;
} else if ((*o)->getTypeId().isDerivedFrom(PartDesign::Subtractive::getClassTypeId())) {
PartDesign::Subtractive* subFeature = static_cast<PartDesign::Subtractive*>(*o);
shape = subFeature->SubShape.getShape()._Shape;
if (shape.IsNull())
return new App::DocumentObjectExecReturn("Shape of subtractive feature is empty");
fuse = false;
} else {
return new App::DocumentObjectExecReturn("Only additive and subtractive features can be transformed");
}
// Transform the add/subshape and build a compound from the transformations,
BRep_Builder builder;
TopoDS_Compound transformedShapes;
builder.MakeCompound(transformedShapes);
std::vector<TopoDS_Shape> v_transformedShapes; // collect all the transformed shapes for intersection testing
std::list<gp_Trsf>::const_iterator t = transformations.begin();
t++; // Skip first transformation, which is always the identity transformation
for (; t != transformations.end(); t++)
{
// Make an explicit copy of the shape because the "true" parameter to BRepBuilderAPI_Transform
// seems to be pretty broken
BRepBuilderAPI_Copy copy(shape);
shape = copy.Shape();
if (shape.IsNull())
throw Base::Exception("Transformed: Linked shape object is empty");
BRepBuilderAPI_Transform mkTrf(shape, *t, false); // No need to copy, now
if (!mkTrf.IsDone())
return new App::DocumentObjectExecReturn("Transformation failed", (*o));
// Check for intersection with support
if (!Part::checkIntersection(support, mkTrf.Shape(), false)) {
Base::Console().Warning("Transformed shape does not intersect support %s: Removed\n", (*o)->getNameInDocument());
// Note: The removal happens in getSolid() after the fuse
rejected.push_back(*t);
}
builder.Add(transformedShapes, mkTrf.Shape());
v_transformedShapes.push_back(mkTrf.Shape());
/*
// Note: This method is only stable for Linear and Polar transformations. No need to
// make an explicit copy of the shape, either
TopoDS_Shape trfShape = shape.Moved(TopLoc_Location(*t));
// Check for intersection with support
Bnd_Box transformed_bb;
BRepBndLib::Add(trfShape, transformed_bb);
if (support_bb.Distance(transformed_bb) > Precision::Confusion()) {
//.........这里部分代码省略.........
开发者ID:juanchijc,项目名称:FreeCAD_sf_master,代码行数:101,代码来源:FeatureTransformed.cpp
示例12: Handle
//=======================================================================
//function : Execute
//purpose :
//=======================================================================
Standard_Integer GEOMImpl_PlaneDriver::Execute(TFunction_Logbook& log) const
{
if (Label().IsNull()) return 0;
Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
GEOMImpl_IPlane aPI (aFunction);
Standard_Integer aType = aFunction->GetType();
TopoDS_Shape aShape;
double aSize = aPI.GetSize() / 2.0;
if (aType == PLANE_PNT_VEC) {
Handle(GEOM_Function) aRefPnt = aPI.GetPoint();
Handle(GEOM_Function) aRefVec = aPI.GetVector();
TopoDS_Shape aShape1 = aRefPnt->GetValue();
TopoDS_Shape aShape2 = aRefVec->GetValue();
if (aShape1.ShapeType() != TopAbs_VERTEX ||
aShape2.ShapeType() != TopAbs_EDGE) return 0;
gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
TopoDS_Edge anE = TopoDS::Edge(aShape2);
TopoDS_Vertex V1, V2;
TopExp::Vertices(anE, V1, V2, Standard_True);
if (!V1.IsNull() && !V2.IsNull()) {
gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
gp_Pln aPln (aP, aV);
aShape = BRepBuilderAPI_MakeFace(aPln, -aSize, +aSize, -aSize, +aSize).Shape();
}
} else if (aType == PLANE_THREE_PNT) {
Handle(GEOM_Function) aRefPnt1 = aPI.GetPoint1();
Handle(GEOM_Function) aRefPnt2 = aPI.GetPoint2();
Handle(GEOM_Function) aRefPnt3 = aPI.GetPoint3();
TopoDS_Shape aShape1 = aRefPnt1->GetValue();
TopoDS_Shape aShape2 = aRefPnt2->GetValue();
TopoDS_Shape aShape3 = aRefPnt3->GetValue();
if (aShape1.ShapeType() != TopAbs_VERTEX ||
aShape2.ShapeType() != TopAbs_VERTEX ||
aShape3.ShapeType() != TopAbs_VERTEX) return 0;
gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShape3));
if (aP1.Distance(aP2) < gp::Resolution() ||
aP1.Distance(aP3) < gp::Resolution() ||
aP2.Distance(aP3) < gp::Resolution())
Standard_ConstructionError::Raise("Plane creation aborted: coincident points given");
if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
Standard_ConstructionError::Raise("Plane creation aborted: points lay on one line");
GC_MakePlane aMakePlane (aP1, aP2, aP3);
aShape = BRepBuilderAPI_MakeFace(aMakePlane, -aSize, +aSize, -aSize, +aSize).Shape();
} else if (aType == PLANE_FACE) {
Handle(GEOM_Function) aRef = aPI.GetFace();
TopoDS_Shape aRefShape = aRef->GetValue();
//if (aRefShape.ShapeType() != TopAbs_FACE) return 0;
//Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(aRefShape));
//if (!aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
// Standard_TypeMismatch::Raise("Plane creation aborted: non-planar face given as argument");
//}
//aShape = BRepBuilderAPI_MakeFace(aGS, -aSize, +aSize, -aSize, +aSize).Shape();
gp_Ax3 anAx3 = GEOMImpl_IMeasureOperations::GetPosition(aRefShape);
gp_Pln aPln (anAx3);
aShape = BRepBuilderAPI_MakeFace(aPln, -aSize, +aSize, -aSize, +aSize).Shape();
}
else if (aType == PLANE_TANGENT_FACE)
{
Handle(GEOM_Function) aRefFace = aPI.GetFace();
TopoDS_Shape aShape1 = aRefFace->GetValue();
if(aShape1.IsNull())
Standard_TypeMismatch::Raise("Plane was not created.Basis face was not specified");
TopoDS_Face aFace = TopoDS::Face(aShape1);
Standard_Real aKoefU = aPI.GetParameterU();
Standard_Real aKoefV = aPI.GetParameterV();
Standard_Real aUmin,aUmax,aVmin,aVmax;
ShapeAnalysis::GetFaceUVBounds(aFace,aUmin,aUmax,aVmin,aVmax);
Standard_Real aDeltaU = aUmax - aUmin;
Standard_Real aDeltaV = aVmax - aVmin;
Standard_Real aParamU = aUmin + aDeltaU*aKoefU;
Standard_Real aParamV = aVmin + aDeltaV*aKoefV;
Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
if(aSurf.IsNull())
Standard_TypeMismatch::Raise("Plane was not created.Base surface is absent");
gp_Vec aVecU,aVecV;
gp_Pnt aPLoc;
aSurf->D1(aParamU,aParamV,aPLoc,aVecU,aVecV);
BRepTopAdaptor_FClass2d clas(aFace,Precision::PConfusion());
TopAbs_State stOut= clas.PerformInfinitePoint();
gp_Pnt2d aP2d(aParamU,aParamV);
TopAbs_State st= clas.Perform(aP2d);
if(st == stOut)
Standard_TypeMismatch::Raise("Plane was not created.Point lies outside the face");
gp_Vec aNorm = aVecU^aVecV;
gp_Ax3 anAxis(aPLoc,gp_Dir(aNorm),gp_Dir(aVecU));
gp_Pln aPlane(anAxis);
BRepBuilderAPI_MakeFace aTool(aPlane, -aSize, +aSize, -aSize, +aSize);
if(aTool.IsDone())
aShape = aTool.Shape();
//.........这里部分代码省略.........
开发者ID:hmeyer,项目名称:salome-geom,代码行数:101,代码来源:GEOMImpl_PlaneDriver.cpp
示例13: ImportIGES
SALOME_WNT_EXPORT
TopoDS_Shape ImportIGES (const TCollection_AsciiString& theFileName,
const TCollection_AsciiString& theFormatName,
TCollection_AsciiString& theError,
const TDF_Label& theShapeLabel)
{
IGESControl_Reader aReader;
TopoDS_Shape aResShape;
Interface_Static::SetCVal("xstep.cascade.unit","M");
try {
IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
if (status == IFSelect_RetDone) {
if( theFormatName == "IGES_UNIT" ) {
Handle(IGESData_IGESModel) aModel =
Handle(IGESData_IGESModel)::DownCast(aReader.Model());
gp_Pnt P(1.0,0.0,0.0);
if(!aModel.IsNull()) {
Handle(TCollection_HAsciiString) aUnitName =
aModel->GlobalSection().UnitName();
//cout<<"aUnitName = "<<aUnitName->ToCString()<<endl;
//cout<<"aUnitFlag = "<<aModel->GlobalSection().UnitFlag()<<endl;
if( aUnitName->String()=="MM" ) {
P = gp_Pnt(0.001,0.0,0.0);
}
else if( aUnitName->String()=="CM" ) {
P = gp_Pnt(0.01,0.0,0.0);
}
}
BRep_Builder B;
TopoDS_Vertex V;
B.MakeVertex(V,P,1.e-7);
aResShape = V;
return aResShape;
}
if( theFormatName == "IGES_SCALE" ) {
//cout<<"need re-scale a model"<<endl;
// set UnitFlag to 'meter'
Handle(IGESData_IGESModel) aModel =
Handle(IGESData_IGESModel)::DownCast(aReader.Model());
if(!aModel.IsNull()) {
IGESData_GlobalSection aGS = aModel->GlobalSection();
aGS.SetUnitFlag(6);
aModel->SetGlobalSection(aGS);
}
}
MESSAGE("ImportIGES : all Geometry Transfer");
//OCC 5.1.2 porting
// aReader.Clear();
// aReader.TransferRoots(false);
aReader.ClearShapes();
aReader.TransferRoots();
MESSAGE("ImportIGES : count of shapes produced = " << aReader.NbShapes());
aResShape = aReader.OneShape();
// BEGIN: Store names of sub-shapes from file
Handle(Interface_InterfaceModel) Model = aReader.WS()->Model();
Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader();
if (!TR.IsNull()) {
Handle(Transfer_TransientProcess) TP = /*TransientProcess();*/TR->TransientProcess();
Standard_Integer nb = Model->NbEntities();
for (Standard_Integer i = 1; i <= nb; i++) {
Handle(IGESData_IGESEntity) ent = Handle(IGESData_IGESEntity)::DownCast(Model->Value(i));
if (ent.IsNull() || ! ent->HasName()) continue;
// find target shape
Handle(Transfer_Binder) binder = TP->Find(ent);
if (binder.IsNull()) continue;
TopoDS_Shape S = TransferBRep::ShapeResult(binder);
if (S.IsNull()) continue;
// create label and set shape
TDF_Label L;
TDF_TagSource aTag;
L = aTag.NewChild(theShapeLabel);
TNaming_Builder tnBuild (L);
tnBuild.Generated(S);
// set a name
TCollection_AsciiString string = ent->NameValue()->String();
string.LeftAdjust();
string.RightAdjust();
TCollection_ExtendedString str (string);
TDataStd_Name::Set(L, str);
}
}
// END: Store names
} else {
// switch (status) {
// case IFSelect_RetVoid:
// theError = "Nothing created or No data to process";
// break;
// case IFSelect_RetError:
// theError = "Error in command or input data";
// break;
// case IFSelect_RetFail:
// theError = "Execution was run, but has failed";
//.........这里部分代码省略.........
开发者ID:dbarbier,项目名称:pythonocc,代码行数:101,代码来源:ExchangeIGES_Import.cpp
示例14: Handle
//=======================================================================
//function : Execute
//purpose :
//=======================================================================
Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const
{
if (Label().IsNull()) return 0;
Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
if (aFunction.IsNull()) return 0;
GEOMImpl_IRotate RI(aFunction);
gp_Trsf aTrsf;
gp_Pnt aCP, aP1, aP2;
Standard_Integer aType = aFunction->GetType();
Handle(GEOM_Function) anOriginalFunction = RI.GetOriginal();
if (anOriginalFunction.IsNull()) return 0;
TopoDS_Shape aShape, anOriginal = anOriginalFunction->GetValue();
if (anOriginal.IsNull()) return 0;
if (aType == ROTATE || aType == ROTATE_COPY) {
Handle(GEOM_Function) anAxis = RI.GetAxis();
if (anAxis.IsNull()) return 0;
TopoDS_Shape A = anAxis->GetValue();
if (A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0;
TopoDS_Edge anEdge = TopoDS::Edge(A);
gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
gp_Dir aDir(gp_Vec(aP1, aP2));
gp_Ax1 anAx1(aP1, aDir);
Standard_Real anAngle = RI.GetAngle();
if (fabs(anAngle) < Precision::Angular()) anAngle += 2*PI; // NPAL19665,19769
aTrsf.SetRotation(anAx1, anAngle);
//NPAL18620: performance problem: multiple locations are accumulated
// in shape and need a great time to process
//BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
//aShape = aTransformation.Shape();
TopLoc_Location aLocOrig = anOriginal.Location();
gp_Trsf aTrsfOrig = aLocOrig.Transformation();
//TopLoc_Location aLocRes (aTrsf * aTrsfOrig); // gp_Trsf::Multiply() has a bug
aTrsfOrig.PreMultiply(aTrsf);
TopLoc_Location aLocRes (aTrsfOrig);
aShape = anOriginal.Located(aLocRes);
}
else if (aType == ROTATE_THREE_POINTS || aType == ROTATE_THREE_POINTS_COPY) {
Handle(GEOM_Function) aCentPoint = RI.GetCentPoint();
Handle(GEOM_Function) aPoint1 = RI.GetPoint1();
Handle(GEOM_Function) aPoint2 = RI.GetPoint2();
if(aCentPoint.IsNull() || aPoint1.IsNull() || aPoint2.IsNull()) return 0;
TopoDS_Shape aCV = aCentPoint->GetValue();
TopoDS_Shape aV1 = aPoint1->GetValue();
TopoDS_Shape aV2 = aPoint2->GetValue();
if(aCV.IsNull() || aCV.ShapeType() != TopAbs_VERTEX) return 0;
if(aV1.IsNull() || aV1.ShapeType() != TopAbs_VERTEX) return 0;
if(aV2.IsNull() || aV2.ShapeType() != TopAbs_VERTEX) return 0;
aCP = BRep_Tool::Pnt(TopoDS::Vertex(aCV));
aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aV1));
aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aV2));
gp_Vec aVec1 (aCP, aP1);
gp_Vec aVec2 (aCP, aP2);
gp_Dir aDir (aVec1 ^ aVec2);
gp_Ax1 anAx1 (aCP, aDir);
Standard_Real anAngle = aVec1.Angle(aVec2);
if (fabs(anAngle) < Precision::Angular()) anAngle += 2*PI; // NPAL19665
aTrsf.SetRotation(anAx1, anAngle);
//NPAL18620: performance problem: multiple locations are accumulated
// in shape and need a great time to process
//BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
//aShape = aTransformation.Shape();
TopLoc_Location aLocOrig = anOriginal.Location();
gp_Trsf aTrsfOrig = aLocOrig.Transformation();
//TopLoc_Location aLocRes (aTrsf * aTrsfOrig); // gp_Trsf::Multiply() has a bug
aTrsfOrig.PreMultiply(aTrsf);
TopLoc_Location aLocRes (aTrsfOrig);
aShape = anOriginal.Located(aLocRes);
}
else if (aType == ROTATE_1D) {
//Get direction
Handle(GEOM_Function) anAxis = RI.GetAxis();
if(anAxis.IsNull()) return 0;
TopoDS_Shape A = anAxis->GetValue();
if(A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0;
TopoDS_Edge anEdge = TopoDS::Edge(A);
gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
gp_Dir D(gp_Vec(aP1, aP2));
gp_Ax1 AX1(aP1, D);
Standard_Integer nbtimes = RI.GetNbIter1();
Standard_Real angle = 360.0/nbtimes;
TopoDS_Compound aCompound;
BRep_Builder B;
B.MakeCompound( aCompound );
//.........这里部分代码省略.........
开发者ID:hmeyer,项目名称:salome-geom,代码行数:101,
|
请发表评论