From: nds Date: Wed, 24 Jun 2015 12:18:44 +0000 (+0300) Subject: Issue #555: Infinite boolean state is stored in Result construction. X-Git-Tag: V_1.3.0~196 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5dfebcc3a72f75f043de9880419b39f073af6819;p=modules%2Fshaper.git Issue #555: Infinite boolean state is stored in Result construction. --- diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index 60b9833c3..8a6c2a5d0 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -53,9 +53,10 @@ void ConstructionPlugin_Axis::createAxisByTwoPoints() std::shared_ptr aStart = GeomAlgoAPI_PointBuilder::point(aShape1); std::shared_ptr anEnd = GeomAlgoAPI_PointBuilder::point(aShape2); if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) { - std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd, true); + std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setInfinite(true); aConstr->setShape(anEdge); setResult(aConstr); } @@ -71,6 +72,7 @@ void ConstructionPlugin_Axis::createAxisByCylindricalFace() std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::cylinderAxis(aSelection); ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setInfinite(true); aConstr->setShape(anEdge); setResult(aConstr); } diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp index 549773ab7..adcd4c122 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp @@ -54,6 +54,7 @@ void ConstructionPlugin_Plane::execute() if (!aPlaneFace.get()) return; ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setInfinite(true); aConstr->setShape(aPlaneFace); setResult(aConstr); } @@ -153,7 +154,7 @@ std::shared_ptr ConstructionPlugin_Plane::createPlaneByGeneralEqu std::string kDefaultPlaneSize = "200"; double aSize = Config_PropManager::integer("Sketch planes", "planes_size", kDefaultPlaneSize); aSize *= 4.; - aPlaneFace = GeomAlgoAPI_FaceBuilder::square(aPlane, aSize, true); + aPlaneFace = GeomAlgoAPI_FaceBuilder::square(aPlane, aSize); } return aPlaneFace; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp index fcf8dbb2b..fdf2fc434 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp @@ -18,8 +18,7 @@ #include std::shared_ptr GeomAlgoAPI_EdgeBuilder::line( - std::shared_ptr theStart, std::shared_ptr theEnd, - const bool theInfinite) + std::shared_ptr theStart, std::shared_ptr theEnd) { const gp_Pnt& aStart = theStart->impl(); const gp_Pnt& anEnd = theEnd->impl(); @@ -31,8 +30,6 @@ std::shared_ptr GeomAlgoAPI_EdgeBuilder::line( BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd); std::shared_ptr aRes(new GeomAPI_Edge); TopoDS_Edge anEdge = anEdgeBuilder.Edge(); - if (theInfinite) - anEdge.Infinite(Standard_True); aRes->setImpl(new TopoDS_Shape(anEdge)); return aRes; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h index 1de252482..ffd042b4c 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h @@ -24,10 +24,8 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder /// Creates linear edge by two points. /// \param theStart a first point of an edge /// \param theEnd an end point of an edge - /// \param theInfinite if true, the shape of the edge is infinite. It is used for axis edge. static std::shared_ptr line(std::shared_ptr theStart, - std::shared_ptr theEnd, - const bool theInfinite = false); + std::shared_ptr theEnd); /// Creates edge - axis of the given cylindrical face. The result axis edge is infinite static std::shared_ptr cylinderAxis( std::shared_ptr theCylindricalFace); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp index 9e687d6d2..46a46d233 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp @@ -31,8 +31,7 @@ std::shared_ptr GeomAlgoAPI_FaceBuilder::square( std::shared_ptr GeomAlgoAPI_FaceBuilder::square( std::shared_ptr thePlane, - const double theSize, - const bool theInfinite) + const double theSize) { // half of the size in each direction from the center BRepBuilderAPI_MakeFace aFaceBuilder(thePlane->impl(), @@ -40,8 +39,6 @@ std::shared_ptr GeomAlgoAPI_FaceBuilder::square( -theSize / 2., theSize / 2.); std::shared_ptr aRes(new GeomAPI_Shape); TopoDS_Shape aFace = aFaceBuilder.Face(); - if (theInfinite) - aFace.Infinite(Standard_True); aRes->setImpl(new TopoDS_Shape(aFace/*aFaceBuilder.Face()*/)); return aRes; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h index 7b68fadcb..49ec19c30 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h @@ -30,8 +30,7 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_FaceBuilder /// Creates square planar face by given point of the center, /// normal to the plane and size of square static std::shared_ptr square(std::shared_ptr thePlane, - const double theSize, - const bool theInfinite = false); + const double theSize); /// Returns the plane of the planar face. If it is not planar, returns empty ptr. static std::shared_ptr plane(std::shared_ptr theFace); diff --git a/src/Model/Model_ResultConstruction.cpp b/src/Model/Model_ResultConstruction.cpp index 2a8893a7e..41e1a9b16 100644 --- a/src/Model/Model_ResultConstruction.cpp +++ b/src/Model/Model_ResultConstruction.cpp @@ -46,6 +46,7 @@ Model_ResultConstruction::Model_ResultConstruction() { myIsDisabled = true; // by default it is not initialized and false to be after created myIsInHistory = true; + myIsInfinite = false; myFacesUpToDate = false; setIsConcealed(false); } @@ -80,3 +81,13 @@ std::shared_ptr Model_ResultConstruction::face(const int theIndex) { return myFaces[theIndex]; } + +bool Model_ResultConstruction::isInfinite() +{ + return myIsInfinite; +} + +void Model_ResultConstruction::setInfinite(const bool theInfinite) +{ + myIsInfinite = theInfinite; +} diff --git a/src/Model/Model_ResultConstruction.h b/src/Model/Model_ResultConstruction.h index e50812409..ac07a4a62 100644 --- a/src/Model/Model_ResultConstruction.h +++ b/src/Model/Model_ResultConstruction.h @@ -25,6 +25,7 @@ class Model_ResultConstruction : public ModelAPI_ResultConstruction bool myFacesUpToDate; ///< is true if faces in myuFaces are computed and up to date std::vector > myFaces; ///< stores the up to date faces if they exist bool myIsInHistory; + bool myIsInfinite; public: /// default color for a result construction inline static const std::string& DEFAULT_COLOR() @@ -59,6 +60,11 @@ class Model_ResultConstruction : public ModelAPI_ResultConstruction /// if the construction result may be used as faces, this method returns face by zero based index MODEL_EXPORT virtual std::shared_ptr face(const int theIndex); + /// By default object is not infinite. + MODEL_EXPORT virtual bool isInfinite(); + /// Sets the flag that it is infinite + MODEL_EXPORT virtual void setInfinite(const bool theInfinite); + protected: /// Makes a body on the given feature Model_ResultConstruction(); diff --git a/src/ModelAPI/ModelAPI_ResultConstruction.h b/src/ModelAPI/ModelAPI_ResultConstruction.h index 6040b35a5..f24fb0d90 100644 --- a/src/ModelAPI/ModelAPI_ResultConstruction.h +++ b/src/ModelAPI/ModelAPI_ResultConstruction.h @@ -43,6 +43,11 @@ class ModelAPI_ResultConstruction : public ModelAPI_Result virtual int facesNum() = 0; /// if the construction result may be used as faces, this method returns face by zero based index virtual std::shared_ptr face(const int theIndex) = 0; + + /// By default object is not infinite. + virtual bool isInfinite() = 0; + /// Sets the flag that it is infinite + virtual void setInfinite(const bool theInfinite) = 0; }; //! Pointer on feature object diff --git a/src/PartSet/PartSet_FilterInfinite.cpp b/src/PartSet/PartSet_FilterInfinite.cpp index 015701265..3feadea09 100755 --- a/src/PartSet/PartSet_FilterInfinite.cpp +++ b/src/PartSet/PartSet_FilterInfinite.cpp @@ -6,6 +6,10 @@ #include "PartSet_FilterInfinite.h" +#include +#include +#include + #include #include #include @@ -14,30 +18,37 @@ IMPLEMENT_STANDARD_HANDLE(PartSet_FilterInfinite, SelectMgr_Filter); IMPLEMENT_STANDARD_RTTIEXT(PartSet_FilterInfinite, SelectMgr_Filter); +PartSet_FilterInfinite::PartSet_FilterInfinite(ModuleBase_IWorkshop* theWorkshop) +: SelectMgr_Filter(), myWorkshop(theWorkshop) +{ +} + Standard_Boolean PartSet_FilterInfinite::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const { Standard_Boolean aValid = Standard_True; - Handle(AIS_InteractiveObject) anAISObj = - Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable()); - if (!anAISObj.IsNull()) { - Handle(AIS_InteractiveObject) anObj = - Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable()); - Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(anObj); - if (!aAISShape.IsNull()) { - TopoDS_Shape anAISShape = aAISShape->Shape(); - if (!anAISShape.IsNull() && anAISShape.Infinite()) { - aValid = Standard_False; + + ModuleBase_ViewerPrs aPrs; + myWorkshop->selection()->fillPresentation(aPrs, theOwner); + ResultPtr aResult = myWorkshop->selection()->getResult(aPrs); + // to filter infinite construction results + if (aResult.get() && aResult->groupName() == ModelAPI_ResultConstruction::group()) { + ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aResult); + if (aConstruction.get() && aConstruction->isInfinite()) { + Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner); + if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) { + const TopoDS_Shape& aShape = aBRepOwner->Shape(); + TopAbs_ShapeEnum anOwnerShapeType = aShape.ShapeType(); + + TopAbs_ShapeEnum aResultShapeType = TopAbs_SHAPE; + GeomShapePtr aResultShape = aResult->shape(); + if (aResultShape.get()) { + TopoDS_Shape aResultTopoShape = aResultShape->impl(); + aResultShapeType = aResultTopoShape.ShapeType(); + } // for infinite object, the selection is possible only for shapes of owners, which are coincide // to the shape of corresponded AIS object. In other words, for axis, only edge can be selected // (vertices are not selectable), for planes, only faces can be selected (not edges or vertices) - TopoDS_Shape anOwnerShape; - Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast(theOwner); - if( !aBRO.IsNull() ) { - anOwnerShape = aBRO->Shape(); - if (!anOwnerShape.IsNull()) { - aValid = anAISShape.ShapeType() == anOwnerShape.ShapeType(); - } - } + aValid = anOwnerShapeType == aResultShapeType; } } } diff --git a/src/PartSet/PartSet_FilterInfinite.h b/src/PartSet/PartSet_FilterInfinite.h index 8fe53055b..f6caa6666 100755 --- a/src/PartSet/PartSet_FilterInfinite.h +++ b/src/PartSet/PartSet_FilterInfinite.h @@ -11,6 +11,8 @@ #include +class ModuleBase_IWorkshop; + /** * \class PartSet_FilterInfinite * \ingroup Modules @@ -22,14 +24,17 @@ class PartSet_FilterInfinite : public SelectMgr_Filter public: /// Constructor /// \param theWorkshop a pointer to workshop - PartSet_FilterInfinite() - : SelectMgr_Filter() {} + PartSet_FilterInfinite(ModuleBase_IWorkshop* theWorkshop); /// Returns True if selected presentation can be selected /// \param theOwner an owner of the persentation Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const; DEFINE_STANDARD_RTTI(PartSet_FilterInfinite) + +protected: + /// Reference to workshop + ModuleBase_IWorkshop* myWorkshop; }; #endif \ No newline at end of file diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 6bbc85002..2be0fb987 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -135,7 +135,7 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED)); mySelectionFilters.Append(new PartSet_GlobalFilter(myWorkshop)); - mySelectionFilters.Append(new PartSet_FilterInfinite()); + mySelectionFilters.Append(new PartSet_FilterInfinite(myWorkshop)); } PartSet_Module::~PartSet_Module()