//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_CylinderDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_ICylinder aCI (aFunction); Standard_Integer aType = aFunction->GetType(); gp_Pnt aP; gp_Vec aV; if (aType == CYLINDER_R_H) { aP = gp::Origin(); aV = gp::DZ(); } else if (aType == CYLINDER_PNT_VEC_R_H) { Handle(GEOM_Function) aRefPoint = aCI.GetPoint(); Handle(GEOM_Function) aRefVector = aCI.GetVector(); TopoDS_Shape aShapePnt = aRefPoint->GetValue(); TopoDS_Shape aShapeVec = aRefVector->GetValue(); if (aShapePnt.IsNull() || aShapeVec.IsNull()) { Standard_NullObject::Raise("Cylinder creation aborted: point or vector is not defined"); } if (aShapePnt.ShapeType() != TopAbs_VERTEX || aShapeVec.ShapeType() != TopAbs_EDGE) { Standard_TypeMismatch::Raise("Cylinder creation aborted: point or vector shapes has wrong type"); } aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); TopoDS_Edge anE = TopoDS::Edge(aShapeVec); TopoDS_Vertex V1, V2; TopExp::Vertices(anE, V1, V2, Standard_True); if (V1.IsNull() || V2.IsNull()) { Standard_NullObject::Raise("Cylinder creation aborted: vector is not defined"); } aV = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2)); } else { return 0; } if (aCI.GetH() < 0.0) aV.Reverse(); gp_Ax2 anAxes (aP, aV); BRepPrimAPI_MakeCylinder MC (anAxes, aCI.GetR(), Abs(aCI.GetH())); MC.Build(); if (!MC.IsDone()) { StdFail_NotDone::Raise("Cylinder can't be computed from the given parameters"); } TopoDS_Shape aShape = MC.Shape(); if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }
//======================================================================= //function : ShapeToDouble //purpose : used by CompareShapes::operator() //======================================================================= std::pair<double, double> GEOMUtils::ShapeToDouble (const TopoDS_Shape& S, bool isOldSorting) { // Computing of CentreOfMass gp_Pnt GPoint; double Len; if (S.ShapeType() == TopAbs_VERTEX) { GPoint = BRep_Tool::Pnt(TopoDS::Vertex(S)); Len = (double)S.Orientation(); } else { GProp_GProps GPr; // BEGIN: fix for Mantis issue 0020842 if (isOldSorting) { BRepGProp::LinearProperties(S, GPr); } else { if (S.ShapeType() == TopAbs_EDGE || S.ShapeType() == TopAbs_WIRE) { BRepGProp::LinearProperties(S, GPr); } else if (S.ShapeType() == TopAbs_FACE || S.ShapeType() == TopAbs_SHELL) { BRepGProp::SurfaceProperties(S, GPr); } else { BRepGProp::VolumeProperties(S, GPr); } } // END: fix for Mantis issue 0020842 GPoint = GPr.CentreOfMass(); Len = GPr.Mass(); } double dMidXYZ = GPoint.X() * 999.0 + GPoint.Y() * 99.0 + GPoint.Z() * 0.9; return std::make_pair(dMidXYZ, Len); }
bool ProfileBased::isQuasiEqual(const TopoDS_Shape& s1, const TopoDS_Shape& s2) const { if (s1.ShapeType() != s2.ShapeType()) return false; TopTools_IndexedMapOfShape map1, map2; TopExp::MapShapes(s1, TopAbs_VERTEX, map1); TopExp::MapShapes(s2, TopAbs_VERTEX, map2); if (map1.Extent() != map2.Extent()) return false; std::vector<gp_Pnt> p1; for (int i=1; i<=map1.Extent(); i++) { const TopoDS_Vertex& v = TopoDS::Vertex(map1.FindKey(i)); p1.push_back(BRep_Tool::Pnt(v)); } std::vector<gp_Pnt> p2; for (int i=1; i<=map2.Extent(); i++) { const TopoDS_Vertex& v = TopoDS::Vertex(map2.FindKey(i)); p2.push_back(BRep_Tool::Pnt(v)); } std::sort(p1.begin(), p1.end(), gp_Pnt_Less()); std::sort(p2.begin(), p2.end(), gp_Pnt_Less()); if (p1.size() != p2.size()) return false; std::vector<gp_Pnt>::iterator it = p1.begin(), jt = p2.begin(); for (; it != p1.end(); ++it, ++jt) { if (!(*it).IsEqual(*jt, Precision::Confusion())) return false; } return true; }
const TopoDS_Shape& BRepOffsetAPI_MakeOffsetFix::Shape() { if (myResult.IsNull()) { TopoDS_Shape result = mkOffset.Shape(); if (result.ShapeType() == TopAbs_WIRE) { MakeWire(result); } else if (result.ShapeType() == TopAbs_COMPOUND) { BRep_Builder builder; TopoDS_Compound comp; builder.MakeCompound(comp); TopExp_Explorer xp(result, TopAbs_WIRE); while (xp.More()) { TopoDS_Wire wire = TopoDS::Wire(xp.Current()); MakeWire(wire); builder.Add(comp, wire); xp.Next(); } result = comp; } myResult = result; } return myResult; }
//======================================================================= //function : AddPointOnEdge //purpose : //======================================================================= Standard_Boolean GEOMImpl_HealingDriver::AddPointOnEdge (GEOMImpl_IHealing* theHI, const TopoDS_Shape& theOriginalShape, TopoDS_Shape& theOutShape) const { Standard_Boolean isByParameter = theHI->GetIsByParameter(); Standard_Integer anIndex = theHI->GetIndex(); Standard_Real aValue = theHI->GetDevideEdgeValue(); ShHealOper_EdgeDivide aHealer (theOriginalShape); Standard_Boolean aResult = Standard_False; if (anIndex == -1) { // apply algorythm for the whole shape which is EDGE if (theOriginalShape.ShapeType() == TopAbs_EDGE) aResult = aHealer.Perform(TopoDS::Edge(theOriginalShape), aValue, isByParameter); } else { TopTools_IndexedMapOfShape aShapes; TopExp::MapShapes(theOriginalShape, aShapes); TopoDS_Shape aEdgeShape = aShapes.FindKey(anIndex); if (aEdgeShape.ShapeType() == TopAbs_EDGE) aResult = aHealer.Perform(TopoDS::Edge(aEdgeShape), aValue, isByParameter); } if (aResult) theOutShape = aHealer.GetResultShape(); else raiseNotDoneExeption( aHealer.GetErrorStatus() ); return aResult; }
const Base::Vector3d Constraint::getDirection(const App::PropertyLinkSub &direction) { App::DocumentObject* obj = direction.getValue(); std::vector<std::string> names = direction.getSubValues(); if (names.size() == 0) return Base::Vector3d(0,0,0); std::string subName = names.front(); Part::Feature* feat = static_cast<Part::Feature*>(obj); TopoDS_Shape sh = feat->Shape.getShape().getSubShape(subName.c_str()); gp_Dir dir; if (sh.ShapeType() == TopAbs_FACE) { BRepAdaptor_Surface surface(TopoDS::Face(sh)); if (surface.GetType() == GeomAbs_Plane) { dir = surface.Plane().Axis().Direction(); } else { return Base::Vector3d(0,0,0); // "Direction must be a planar face or linear edge" } } else if (sh.ShapeType() == TopAbs_EDGE) { BRepAdaptor_Curve line(TopoDS::Edge(sh)); if (line.GetType() == GeomAbs_Line) { dir = line.Line().Direction(); } else { return Base::Vector3d(0,0,0); // "Direction must be a planar face or linear edge" } } Base::Vector3d the_direction(dir.X(), dir.Y(), dir.Z()); the_direction.Normalize(); return the_direction; }
App::DocumentObjectExecReturn *Loft::execute(void) { if (Sections.getSize() == 0) return new App::DocumentObjectExecReturn("No sections linked."); 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; } } } 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."); } } Standard_Boolean isSolid = Solid.getValue() ? Standard_True : Standard_False; Standard_Boolean isRuled = Ruled.getValue() ? Standard_True : Standard_False; Standard_Boolean isClosed = Closed.getValue() ? Standard_True : Standard_False; TopoShape myShape; this->Shape.setValue(myShape.makeLoft(profiles, isSolid, isRuled,isClosed)); return App::DocumentObject::StdReturn; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); return new App::DocumentObjectExecReturn(e->GetMessageString()); } }
//======================================================================= //function : GetPosition //purpose : //======================================================================= gp_Ax3 GEOMUtils::GetPosition (const TopoDS_Shape& theShape) { gp_Ax3 aResult; if (theShape.IsNull()) return aResult; // Axes aResult.Transform(theShape.Location().Transformation()); if (theShape.ShapeType() == TopAbs_FACE) { Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape)); if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) { Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS); gp_Pln aPln = aGPlane->Pln(); aResult = aPln.Position(); // In case of reverse orinetation of the face invert the plane normal // (the face's normal does not mathc the plane's normal in this case) if(theShape.Orientation() == TopAbs_REVERSED) { gp_Dir Vx = aResult.XDirection(); gp_Dir N = aResult.Direction().Mirrored(Vx); gp_Pnt P = aResult.Location(); aResult = gp_Ax3(P, N, Vx); } } } // Origin gp_Pnt aPnt; TopAbs_ShapeEnum aShType = theShape.ShapeType(); if (aShType == TopAbs_VERTEX) { aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape)); } else { if (aShType == TopAbs_COMPOUND) { aShType = GetTypeOfSimplePart(theShape); } GProp_GProps aSystem; if (aShType == TopAbs_EDGE || aShType == TopAbs_WIRE) BRepGProp::LinearProperties(theShape, aSystem); else if (aShType == TopAbs_FACE || aShType == TopAbs_SHELL) BRepGProp::SurfaceProperties(theShape, aSystem); else BRepGProp::VolumeProperties(theShape, aSystem); aPnt = aSystem.CentreOfMass(); } aResult.SetLocation(aPnt); return aResult; }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_TorusDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_ITorus aCI (aFunction); Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; if (aType == TORUS_RR) { aShape = BRepPrimAPI_MakeTorus(aCI.GetRMajor(), aCI.GetRMinor()).Shape(); } else if (aType == TORUS_PNT_VEC_RR) { Handle(GEOM_Function) aRefPoint = aCI.GetCenter(); Handle(GEOM_Function) aRefVector = aCI.GetVector(); TopoDS_Shape aShapePnt = aRefPoint->GetValue(); TopoDS_Shape aShapeVec = aRefVector->GetValue(); if (aShapePnt.ShapeType() != TopAbs_VERTEX) { Standard_TypeMismatch::Raise("Torus Center must be a vertex"); } if (aShapeVec.ShapeType() != TopAbs_EDGE) { Standard_TypeMismatch::Raise("Torus Axis must be an edge"); } gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); TopoDS_Edge anE = TopoDS::Edge(aShapeVec); TopoDS_Vertex V1, V2; TopExp::Vertices(anE, V1, V2, Standard_True); if (V1.IsNull() || V2.IsNull()) { Standard_ConstructionError::Raise("Bad edge for the Torus Axis given"); } gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2)); if (aV.Magnitude() < Precision::Confusion()) { Standard_ConstructionError::Raise ("End vertices of edge, defining the Torus Axis, are too close"); } gp_Ax2 anAxes (aP, aV); BRepPrimAPI_MakeTorus MT (anAxes, aCI.GetRMajor(), aCI.GetRMinor()); if (!MT.IsDone()) MT.Build(); if (!MT.IsDone()) StdFail_NotDone::Raise("Torus construction algorithm has failed"); aShape = MT.Shape(); } else { } if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }
Base::Vector3d ProfileBased::getProfileNormal() const { Base::Vector3d SketchVector(0,0,1); auto obj = getVerifiedObject(true); if(!obj) return SketchVector; // get the Sketch plane if(obj->isDerivedFrom(Part::Part2DObject::getClassTypeId())) { Base::Placement SketchPos = obj->Placement.getValue(); Base::Rotation SketchOrientation = SketchPos.getRotation(); SketchOrientation.multVec(SketchVector,SketchVector); } else { TopoDS_Shape shape = getVerifiedFace(true); if (shape == TopoDS_Shape()) return SketchVector; if (shape.ShapeType() == TopAbs_FACE) { BRepAdaptor_Surface adapt(TopoDS::Face(shape)); double u = adapt.FirstUParameter() + (adapt.LastUParameter() - adapt.FirstUParameter())/2.; double v = adapt.FirstVParameter() + (adapt.LastVParameter() - adapt.FirstVParameter())/2.; BRepLProp_SLProps prop(adapt,u,v,2,Precision::Confusion()); if(prop.IsNormalDefined()) { gp_Pnt pnt; gp_Vec vec; // handles the orientation state of the shape BRepGProp_Face(TopoDS::Face(shape)).Normal(u,v,pnt,vec); SketchVector = Base::Vector3d(vec.X(), vec.Y(), vec.Z()); } } } return SketchVector; }
//======================================================================= //function : CloseContour //purpose : //======================================================================= Standard_Boolean GEOMImpl_HealingDriver::CloseContour (GEOMImpl_IHealing* theHI, const TopoDS_Shape& theOriginalShape, TopoDS_Shape& theOutShape) const { Standard_Boolean isByVertex = theHI->GetIsCommonVertex(); Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires(); ShHealOper_CloseContour aHealer (theOriginalShape); Standard_Boolean aResult = Standard_False; if ( aWires.IsNull() ) { if ( theOriginalShape.ShapeType() == TopAbs_WIRE ) aResult = aHealer.Perform(TopoDS::Wire(theOriginalShape), isByVertex, !isByVertex); } else { TopTools_SequenceOfShape aShapesWires; TopTools_IndexedMapOfShape aShapes; TopExp::MapShapes(theOriginalShape, aShapes); for (int i = 1; i <= aWires->Length(); i++) { int indexOfWire = aWires->Value(i); TopoDS_Shape aWire = aShapes.FindKey(indexOfWire); aShapesWires.Append(aWire); } aResult = aHealer.Perform( aShapesWires, isByVertex, !isByVertex ); } if (aResult) theOutShape = aHealer.GetResultShape(); else raiseNotDoneExeption( aHealer.GetErrorStatus() ); return aResult; }
void StdMeshers_ProjectionSource1D::SetSourceEdge(const TopoDS_Shape& edge) throw ( SALOME_Exception ) { if ( edge.IsNull() ) throw SALOME_Exception(LOCALIZED("Null edge is not allowed")); if ( edge.ShapeType() != TopAbs_EDGE && edge.ShapeType() != TopAbs_COMPOUND ) throw SALOME_Exception(LOCALIZED("Wrong shape type")); if ( !_sourceEdge.IsSame( edge ) ) { _sourceEdge = edge; NotifySubMeshesHypothesisModification(); } }
//======================================================================= // function: IsSplitToReverse // purpose: //======================================================================= Standard_Boolean GEOMAlgo_Tools3D::IsSplitToReverse(const TopoDS_Shape& theSp, const TopoDS_Shape& theSr, IntTools_Context& theCtx) { Standard_Boolean bRet; TopAbs_ShapeEnum aType; // bRet=Standard_False; // aType=theSp.ShapeType(); switch (aType) { case TopAbs_EDGE: { const TopoDS_Edge& aESp=TopoDS::Edge(theSp); const TopoDS_Edge& aESr=TopoDS::Edge(theSr); bRet=GEOMAlgo_Tools3D::IsSplitToReverse(aESp, aESr, theCtx); } break; // case TopAbs_FACE: { const TopoDS_Face& aFSp=TopoDS::Face(theSp); const TopoDS_Face& aFSr=TopoDS::Face(theSr); bRet=GEOMAlgo_Tools3D::IsSplitToReverse(aFSp, aFSr, theCtx); } break; // default: break; } return bRet; }
bool DlgExtrusion::canExtrude(const TopoDS_Shape& shape) const { if (shape.IsNull()) return false; TopAbs_ShapeEnum type = shape.ShapeType(); if (type == TopAbs_VERTEX || type == TopAbs_EDGE || type == TopAbs_WIRE || type == TopAbs_FACE || type == TopAbs_SHELL) return true; if (type == TopAbs_COMPOUND) { TopExp_Explorer xp; xp.Init(shape,TopAbs_SOLID); while (xp.More()) { return false; } xp.Init(shape,TopAbs_COMPSOLID); while (xp.More()) { return false; } return true; } return false; }
bool allow(App::Document*pDoc, App::DocumentObject*pObj, const char*sSubName) { this->canSelect = false; if (!pObj->isDerivedFrom(Part::Feature::getClassTypeId())) return false; if (!sSubName || sSubName[0] == '\0') return false; std::string element(sSubName); if (element.substr(0,4) != "Edge") return false; Part::Feature* fea = static_cast<Part::Feature*>(pObj); try { TopoDS_Shape sub = fea->Shape.getShape().getSubShape(sSubName); if (!sub.IsNull() && sub.ShapeType() == TopAbs_EDGE) { const TopoDS_Edge& edge = TopoDS::Edge(sub); BRepAdaptor_Curve adapt(edge); if (adapt.GetType() == GeomAbs_Line) { gp_Lin line = adapt.Line(); this->loc = line.Location(); this->dir = line.Direction(); this->canSelect = true; return true; } } } catch (...) { } return false; }
TopoDS_Shape ProfileBased::getVerifiedFace(bool silent) const { App::DocumentObject* result = Profile.getValue(); const char* err = nullptr; if (!result) { err = "No profile linked"; } else { if (result->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) { auto wires = getProfileWires(); return Part::FaceMakerCheese::makeFace(wires); } else if(result->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { if(Profile.getSubValues().empty()) err = "Linked object has no subshape specified"; else { const Part::TopoShape& shape = Profile.getValue<Part::Feature*>()->Shape.getShape(); TopoDS_Shape sub = shape.getSubShape(Profile.getSubValues()[0].c_str()); if(sub.ShapeType() == TopAbs_FACE) return TopoDS::Face(sub); else if(sub.ShapeType() == TopAbs_WIRE) { auto wire = TopoDS::Wire(sub); if(!wire.Closed()) err = "Linked wire is not closed"; else { BRepBuilderAPI_MakeFace mk(wire); mk.Build(); return TopoDS::Face(mk.Shape()); } } else err = "Linked Subshape cannot be used"; } } else err = "Linked object is neither Sketch, Part2DObject or Part::Feature"; } if (!silent && err) { throw Base::RuntimeError (err); } return TopoDS_Face(); }
// constructor method int TopoShapeVertexPy::PyInit(PyObject* args, PyObject* /*kwd*/) { double x=0.0,y=0.0,z=0.0; PyObject *object; bool success = false; if (PyArg_ParseTuple(args, "|ddd", &x,&y,&z)) { // do nothing here success = true; } if (!success) { PyErr_Clear(); // set by PyArg_ParseTuple() if (PyArg_ParseTuple(args,"O!",&(Base::VectorPy::Type), &object)) { // Note: must be static_cast, not reinterpret_cast Base::Vector3d* ptr = static_cast<Base::VectorPy*>(object)->getVectorPtr(); x = ptr->x; y = ptr->y; z = ptr->z; success = true; } } if (!success) { PyErr_Clear(); // set by PyArg_ParseTuple() if (PyArg_ParseTuple(args,"O!",&(PyTuple_Type), &object)) { try { Py::Tuple tuple(object); x = Py::Float(tuple.getItem(0)); y = Py::Float(tuple.getItem(1)); z = Py::Float(tuple.getItem(2)); success = true; } catch (const Py::Exception&) { return -1; } } } if (!success) { PyErr_Clear(); // set by PyArg_ParseTuple() if (PyArg_ParseTuple(args,"O!",&(Part::TopoShapePy::Type), &object)) { TopoShape* ptr = static_cast<TopoShapePy*>(object)->getTopoShapePtr(); TopoDS_Shape shape = ptr->_Shape; if (!shape.IsNull() && shape.ShapeType() == TopAbs_VERTEX) { TopoShapeVertexPy::PointerType vert = reinterpret_cast<TopoShapeVertexPy::PointerType>(_pcTwinPointer); vert->_Shape = ptr->_Shape; return 0; } } } if (!success) { PyErr_SetString(PyExc_TypeError, "Either three floats, tuple, vector or vertex expected"); return -1; } TopoShapeVertexPy::PointerType ptr = reinterpret_cast<TopoShapeVertexPy::PointerType>(_pcTwinPointer); BRepBuilderAPI_MakeVertex aBuilder(gp_Pnt(x,y,z)); TopoDS_Shape s = aBuilder.Vertex(); ptr->_Shape = s; return 0; }
bool SMESH_MesherHelper::IsQuadraticSubMesh(const TopoDS_Shape& aSh) { SMESHDS_Mesh* meshDS = GetMeshDS(); // we can create quadratic elements only if all elements // created on subshapes of given shape are quadratic // also we have to fill myNLinkNodeMap myCreateQuadratic = true; mySeamShapeIds.clear(); myDegenShapeIds.clear(); TopAbs_ShapeEnum subType( aSh.ShapeType()==TopAbs_FACE ? TopAbs_EDGE : TopAbs_FACE ); SMDSAbs_ElementType elemType( subType==TopAbs_FACE ? SMDSAbs_Face : SMDSAbs_Edge ); int nbOldLinks = myNLinkNodeMap.size(); TopExp_Explorer exp( aSh, subType ); for (; exp.More() && myCreateQuadratic; exp.Next()) { if ( SMESHDS_SubMesh * subMesh = meshDS->MeshElements( exp.Current() )) { if ( SMDS_ElemIteratorPtr it = subMesh->GetElements() ) { while(it->more()) { const SMDS_MeshElement* e = it->next(); if ( e->GetType() != elemType || !e->IsQuadratic() ) { myCreateQuadratic = false; break; } else { // fill NLinkNodeMap switch ( e->NbNodes() ) { case 3: AddNLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(2)); break; case 6: AddNLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(3)); AddNLinkNode(e->GetNode(1),e->GetNode(2),e->GetNode(4)); AddNLinkNode(e->GetNode(2),e->GetNode(0),e->GetNode(5)); break; case 8: AddNLinkNode(e->GetNode(0),e->GetNode(1),e->GetNode(4)); AddNLinkNode(e->GetNode(1),e->GetNode(2),e->GetNode(5)); AddNLinkNode(e->GetNode(2),e->GetNode(3),e->GetNode(6)); AddNLinkNode(e->GetNode(3),e->GetNode(0),e->GetNode(7)); break; default: myCreateQuadratic = false; break; } } } } } } if ( nbOldLinks == myNLinkNodeMap.size() ) myCreateQuadratic = false; if(!myCreateQuadratic) { myNLinkNodeMap.clear(); } SetSubShape( aSh ); return myCreateQuadratic; }
bool ProfileBased::isParallelPlane(const TopoDS_Shape& s1, const TopoDS_Shape& s2) const { if (s1.ShapeType() == TopAbs_FACE && s2.ShapeType() == TopAbs_FACE) { BRepAdaptor_Surface a1(TopoDS::Face(s1)); BRepAdaptor_Surface a2(TopoDS::Face(s2)); if (a1.GetType() == GeomAbs_Plane && a2.GetType() == GeomAbs_Plane) { gp_Pln p1 = a1.Plane(); gp_Pln p2 = a2.Plane(); const gp_Dir& d1 = p1.Axis().Direction(); const gp_Dir& d2 = p2.Axis().Direction(); if (d1.IsParallel(d2, Precision::Confusion())) return true; } } return false; }
void TaskCheckGeometryResults::goCheck() { Gui::WaitCursor wc; int selectedCount(0), checkedCount(0), invalidShapes(0); std::vector<Gui::SelectionSingleton::SelObj> selection = Gui::Selection().getSelection(); std::vector<Gui::SelectionSingleton::SelObj>::iterator it; ResultEntry *theRoot = new ResultEntry(); for (it = selection.begin(); it != selection.end(); ++it) { selectedCount++; Part::Feature *feature = dynamic_cast<Part::Feature *>((*it).pObject); if (!feature) continue; currentProvider = Gui::Application::Instance->activeDocument()->getViewProvider(feature); if (!currentProvider) continue; TopoDS_Shape shape = feature->Shape.getValue(); QString baseName; QTextStream baseStream(&baseName); baseStream << (*it).DocName; baseStream << "." << (*it).FeatName; if (strlen((*it).SubName) > 0) { shape = feature->Shape.getShape().getSubShape((*it).SubName); baseStream << "." << (*it).SubName; } if (shape.IsNull()) continue; checkedCount++; checkedMap.Clear(); BRepCheck_Analyzer shapeCheck(shape); if (!shapeCheck.IsValid()) { invalidShapes++; ResultEntry *entry = new ResultEntry(); entry->parent = theRoot; entry->shape = shape; entry->name = baseName; entry->type = shapeEnumToString(shape.ShapeType()); entry->error = QObject::tr("Invalid"); entry->viewProvider = currentProvider; getSetupResultBoundingBoxObject().go(entry); theRoot->children.push_back(entry); recursiveCheck(shapeCheck, shape, entry); } } model->setResults(theRoot); treeView->expandAll(); treeView->header()->resizeSections(QHeaderView::ResizeToContents); QString aMessage; QTextStream aStream(&aMessage); aStream << checkedCount << " processed out of " << selectedCount << " selected\n"; aStream << invalidShapes << " invalid shapes."; message->setText(aMessage); Gui::Selection().clearSelection(); }
Standard_Boolean ShHealOper_RemoveFace::removeFaces(const TopoDS_Shell& theShell, TopoDS_Shape& theNewShape) { Standard_Boolean aIsRemove = Standard_False; //TopoDS_Shape aShape = myReShape->Apply(theShape); //removing faces from shell. TopoDS_Iterator aIterFaces(theShell,Standard_False); for(; aIterFaces.More() && myMapFaces.Extent(); aIterFaces.Next()) { if(!myMapFaces.Contains(aIterFaces.Value())) continue; TopoDS_Face aFace = TopoDS::Face( aIterFaces.Value()); removePCurve(aFace); aIsRemove = Standard_True; myContext->Remove(aFace); myMapFaces.Remove(aFace); } if(aIsRemove) { TopoDS_Shape aNewShape = myContext->Apply(theShell); //avoiding empty shell and shell containing one face. TopoDS_Shape aresShape = getResultShell(aNewShape); if(aresShape.IsNull()) { myContext->Remove(aNewShape); theNewShape.Nullify(); } else if(aresShape.ShapeType() == TopAbs_FACE) { myContext->Replace(aNewShape,aresShape); theNewShape = aresShape; } else if(aresShape.ShapeType() == TopAbs_SHELL) { //obtaining correct shell or compound with help class ShapeFix_Shell. Standard_Boolean isManifShell = isManifold(theShell); Handle(ShapeFix_Shell) aFixShell = new ShapeFix_Shell; aFixShell->FixFaceOrientation(TopoDS::Shell(aresShape),Standard_True,!isManifShell); TopoDS_Shape aFixShape = aFixShell->Shape(); TopoDS_Shape areplShape; isReplace(aFixShape,areplShape); myContext->Replace(aNewShape,areplShape); theNewShape = areplShape; } } else theNewShape = theShell; return aIsRemove; }
void SweepWidget::findShapes() { App::Document* activeDoc = App::GetApplication().getActiveDocument(); Gui::Document* activeGui = Gui::Application::Instance->getDocument(activeDoc); if (!activeGui) return; d->document = activeDoc->getName(); std::vector<Part::Feature*> objs = activeDoc->getObjectsOfType<Part::Feature>(); for (std::vector<Part::Feature*>::iterator it = objs.begin(); it!=objs.end(); ++it) { TopoDS_Shape shape = (*it)->Shape.getValue(); if (shape.IsNull()) continue; // also allow compounds with a single face, wire, edge or vertex if (shape.ShapeType() == TopAbs_COMPOUND) { TopoDS_Iterator it(shape); int numChilds=0; TopoDS_Shape child; for (; it.More(); it.Next(), numChilds++) { if (!it.Value().IsNull()) child = it.Value(); } if (numChilds == 1) shape = child; } if (shape.ShapeType() == TopAbs_FACE || shape.ShapeType() == TopAbs_WIRE || shape.ShapeType() == TopAbs_EDGE || shape.ShapeType() == TopAbs_VERTEX) { QString label = QString::fromUtf8((*it)->Label.getValue()); QString name = QString::fromLatin1((*it)->getNameInDocument()); QTreeWidgetItem* child = new QTreeWidgetItem(); child->setText(0, label); child->setToolTip(0, label); child->setData(0, Qt::UserRole, name); Gui::ViewProvider* vp = activeGui->getViewProvider(*it); if (vp) child->setIcon(0, vp->getIcon()); d->ui.selector->availableTreeWidget()->addTopLevelItem(child); } } }
//======================================================================= //function : CompareShapes::operator() //purpose : used by std::sort(), called from SortShapes() //======================================================================= bool GEOMUtils::CompareShapes::operator() (const TopoDS_Shape& theShape1, const TopoDS_Shape& theShape2) { if (!myMap.IsBound(theShape1)) { myMap.Bind(theShape1, ShapeToDouble(theShape1, myIsOldSorting)); } if (!myMap.IsBound(theShape2)) { myMap.Bind(theShape2, ShapeToDouble(theShape2, myIsOldSorting)); } std::pair<double, double> val1 = myMap.Find(theShape1); std::pair<double, double> val2 = myMap.Find(theShape2); double tol = Precision::Confusion(); bool exchange = Standard_False; double dMidXYZ = val1.first - val2.first; if (dMidXYZ >= tol) { exchange = Standard_True; } else if (Abs(dMidXYZ) < tol) { double dLength = val1.second - val2.second; if (dLength >= tol) { exchange = Standard_True; } else if (Abs(dLength) < tol && theShape1.ShapeType() <= TopAbs_FACE) { // PAL17233 // equal values possible on shapes such as two halves of a sphere and // a membrane inside the sphere Bnd_Box box1,box2; BRepBndLib::Add(theShape1, box1); if (!box1.IsVoid()) { BRepBndLib::Add(theShape2, box2); Standard_Real dSquareExtent = box1.SquareExtent() - box2.SquareExtent(); if (dSquareExtent >= tol) { exchange = Standard_True; } else if (Abs(dSquareExtent) < tol) { Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, val1, val2; box1.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); val1 = (aXmin+aXmax)*999.0 + (aYmin+aYmax)*99.0 + (aZmin+aZmax)*0.9; box2.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); val2 = (aXmin+aXmax)*999.0 + (aYmin+aYmax)*99.0 + (aZmin+aZmax)*0.9; if ((val1 - val2) >= tol) { exchange = Standard_True; } } } } } //return val1 < val2; return !exchange; }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_SphereDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_ISphere aCI (aFunction); Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; char aMsg[] = "Sphere creation aborted: radius value less than 1e-07 is not acceptable"; double theAngle = aCI.GetAngle(); if (theAngle == 0.) theAngle = PI * 2.; double theVCoordStart = aCI.GetVCoordStart(); double theVCoordEnd = aCI.GetVCoordEnd(); if (aType == SPHERE_R) { double anR = aCI.GetR(); if (anR < Precision::Confusion()) Standard_ConstructionError::Raise(aMsg); //There seems to be an issue with the BRepPrimAPI_MakeSphere command concerning //the limitations on V coodinates of its parametric space ... (Will not be used for the moment) aShape = BRepPrimAPI_MakeSphere(anR /*, theVCoordStart, theVCoordEnd*/ , theAngle).Shape(); } else if (aType == SPHERE_PNT_R) { double anR = aCI.GetR(); if (anR < Precision::Confusion()) Standard_ConstructionError::Raise(aMsg); Handle(GEOM_Function) aRefPoint = aCI.GetPoint(); TopoDS_Shape aShapePnt = aRefPoint->GetValue(); if (aShapePnt.ShapeType() != TopAbs_VERTEX) Standard_ConstructionError::Raise("Invalid shape given for sphere center: it must be a point"); gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); aShape = BRepPrimAPI_MakeSphere(aP, anR/*, theVCoordStart, theVCoordEnd*/, theAngle).Shape(); } else { } if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }
bool ProfileBased::isEqualGeometry(const TopoDS_Shape& s1, const TopoDS_Shape& s2) const { if (s1.ShapeType() == TopAbs_FACE && s2.ShapeType() == TopAbs_FACE) { BRepAdaptor_Surface a1(TopoDS::Face(s1)); BRepAdaptor_Surface a2(TopoDS::Face(s2)); if (a1.GetType() == GeomAbs_Plane && a2.GetType() == GeomAbs_Plane) { gp_Pln p1 = a1.Plane(); gp_Pln p2 = a2.Plane(); if (p1.Distance(p2.Location()) < Precision::Confusion()) { const gp_Dir& d1 = p1.Axis().Direction(); const gp_Dir& d2 = p2.Axis().Direction(); if (d1.IsParallel(d2, Precision::Confusion())) return true; } } } else if (s1.ShapeType() == TopAbs_EDGE && s2.ShapeType() == TopAbs_EDGE) { } else if (s1.ShapeType() == TopAbs_VERTEX && s2.ShapeType() == TopAbs_VERTEX) { gp_Pnt p1 = BRep_Tool::Pnt(TopoDS::Vertex(s1)); gp_Pnt p2 = BRep_Tool::Pnt(TopoDS::Vertex(s2)); return p1.Distance(p2) < Precision::Confusion(); } return false; }
Standard_Boolean ShHealOper_RemoveFace::removeFaces(const TopoDS_Solid& theShape, TopoDS_Shape& theNewShape) { Standard_Boolean isDone = Standard_False; TopoDS_Solid aSol; BRep_Builder aB; aB.MakeSolid(aSol); TopoDS_Compound aComp; aB.MakeCompound(aComp); Standard_Boolean isAddSol = Standard_False, isAddComp = Standard_False; //firslty faces will be deleted from each shell. TopoDS_Iterator aItSol(theShape,Standard_False); for( ; aItSol.More(); aItSol.Next()) { TopoDS_Shape aSh = aItSol.Value(); TopoDS_Shape aNewShape; if(removeFaces(aSh,aNewShape)) isDone = Standard_True; if(aNewShape.IsNull()) continue; else if(aNewShape.ShapeType() == TopAbs_SHELL ) { aB.Add(aSol,aNewShape); isAddSol = Standard_True; } else { aB.Add(aComp,aNewShape); isAddComp = Standard_True; } } if(isDone) { //for getting correct solids class ShapeFix_Solid will be used. if(isAddSol) { Handle(ShapeFix_Solid) aSfSol = new ShapeFix_Solid(aSol); aSfSol->FixShellMode()= Standard_False; aSfSol->Perform(); TopoDS_Shape aresSol = aSfSol->Shape(); if(!isAddComp) theNewShape = aresSol; else aB.Add(aComp,aresSol); } else if(isAddComp) theNewShape = aComp; else theNewShape.Nullify(); } else theNewShape = theShape; return isDone; }
void StdMeshers_ProjectionSource1D::SetVertexAssociation(const TopoDS_Shape& sourceVertex, const TopoDS_Shape& targetVertex) throw ( SALOME_Exception ) { if ( sourceVertex.IsNull() != targetVertex.IsNull() ) throw SALOME_Exception(LOCALIZED("Two or none vertices must be provided")); if ( !sourceVertex.IsNull() ) { if ( sourceVertex.ShapeType() != TopAbs_VERTEX || targetVertex.ShapeType() != TopAbs_VERTEX ) throw SALOME_Exception(LOCALIZED("Wrong shape type")); } if ( !_sourceVertex.IsSame( sourceVertex ) || !_targetVertex.IsSame( targetVertex ) ) { _sourceVertex = TopoDS::Vertex( sourceVertex ); _targetVertex = TopoDS::Vertex( targetVertex ); NotifySubMeshesHypothesisModification(); } }
unsigned int GetNumberOfSubshapes(const TopoDS_Shape &shape) { if (shape.ShapeType() == TopAbs_COMPOUND) { unsigned int n = 0; for (TopoDS_Iterator anIter(shape); anIter.More(); anIter.Next()) { n++; } return n; } else { return 0; } }
void TaskCheckGeometryResults::recursiveCheck(const BRepCheck_Analyzer &shapeCheck, const TopoDS_Shape &shape, ResultEntry *parent) { ResultEntry *branchNode = parent; BRepCheck_ListIteratorOfListOfStatus listIt; if (!shapeCheck.Result(shape).IsNull() && !checkedMap.Contains(shape)) { listIt.Initialize(shapeCheck.Result(shape)->Status()); if (listIt.Value() != BRepCheck_NoError) { ResultEntry *entry = new ResultEntry(); entry->parent = parent; entry->shape = shape; entry->buildEntryName(); entry->type = shapeEnumToString(shape.ShapeType()); entry->error = checkStatusToString(listIt.Value()); entry->viewProviderRoot = currentSeparator; entry->viewProviderRoot->ref(); dispatchError(entry, listIt.Value()); parent->children.push_back(entry); branchNode = entry; } } checkedMap.Add(shape); if (shape.ShapeType() == TopAbs_SOLID) checkSub(shapeCheck, shape, TopAbs_SHELL, branchNode); if (shape.ShapeType() == TopAbs_EDGE) checkSub(shapeCheck, shape, TopAbs_VERTEX, branchNode); if (shape.ShapeType() == TopAbs_FACE) { checkSub(shapeCheck, shape, TopAbs_WIRE, branchNode); checkSub(shapeCheck, shape, TopAbs_EDGE, branchNode); checkSub(shapeCheck, shape, TopAbs_VERTEX, branchNode); } for (TopoDS_Iterator it(shape); it.More(); it.Next()) recursiveCheck(shapeCheck, it.Value(), branchNode); }
//======================================================================= //function : SupressFaces //purpose : //======================================================================= void SuppressFacesRec (const TopTools_SequenceOfShape& theShapesFaces, const TopoDS_Shape& theOriginalShape, TopoDS_Shape& theOutShape) { if ((theOriginalShape.ShapeType() != TopAbs_COMPOUND && theOriginalShape.ShapeType() != TopAbs_COMPSOLID)) { ShHealOper_RemoveFace aHealer (theOriginalShape); Standard_Boolean aResult = aHealer.Perform(theShapesFaces); if (aResult) theOutShape = aHealer.GetResultShape(); else raiseNotDoneExeption(aHealer.GetErrorStatus()); } else { BRep_Builder BB; TopoDS_Compound CC; BB.MakeCompound(CC); TopTools_MapOfShape mapShape; TopoDS_Iterator It (theOriginalShape, Standard_True, Standard_True); for (; It.More(); It.Next()) { TopoDS_Shape aShape_i = It.Value(); if (mapShape.Add(aShape_i)) { // check, if current shape contains at least one of faces to be removed bool isFound = false; TopTools_IndexedMapOfShape aShapes_i; TopExp::MapShapes(aShape_i, aShapes_i); for (int i = 1; i <= theShapesFaces.Length() && !isFound; i++) { const TopoDS_Shape& aFace_i = theShapesFaces.Value(i); if (aShapes_i.Contains(aFace_i)) isFound = true; } if (isFound) { TopoDS_Shape anOutSh_i; SuppressFacesRec(theShapesFaces, aShape_i, anOutSh_i); if ( !anOutSh_i.IsNull() ) BB.Add(CC, anOutSh_i); } else { // nothing to do BB.Add(CC, aShape_i); } } } theOutShape = CC; } }