From: vsv Date: Mon, 16 Mar 2015 14:18:58 +0000 (+0300) Subject: PositionMgr improvement X-Git-Tag: V_1.1.0~130 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e7f1ac7ab6a29efa09daecae84b2add0ff630c8d;p=modules%2Fshaper.git PositionMgr improvement --- diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 0b98b3328..06167aa91 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -143,7 +143,7 @@ - + diff --git a/src/SketcherPrs/SketcherPrs_Parallel.cpp b/src/SketcherPrs/SketcherPrs_Parallel.cpp index 380c15f9c..09aebca45 100644 --- a/src/SketcherPrs/SketcherPrs_Parallel.cpp +++ b/src/SketcherPrs/SketcherPrs_Parallel.cpp @@ -56,17 +56,20 @@ void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& t { prepareAspect(); - std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); + + std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(aObj1); if (aLine1.get() == NULL) return; - std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B()); + std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(aObj2); if (aLine2.get() == NULL) return; - + SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); - gp_Pnt aP1 = aMgr->getPosition(aLine1, this); - gp_Pnt aP2 = aMgr->getPosition(aLine2, this); + gp_Pnt aP1 = aMgr->getPosition(aObj1, this); + gp_Pnt aP2 = aMgr->getPosition(aObj2, this); Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); aGroup->SetPrimitivesAspect(myAspect); diff --git a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp index 0c9e45da2..287c5fe69 100644 --- a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp +++ b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp @@ -42,7 +42,7 @@ SketcherPrs_Perpendicular::SketcherPrs_Perpendicular(SketchPlugin_Constraint* th { myPntArray = new Graphic3d_ArrayOfPoints(2); myPntArray->AddVertex(0., 0., 0.); - myPntArray->AddVertex(0. ,0., 0.); + myPntArray->AddVertex(0., 0., 0.); } void SketcherPrs_Perpendicular::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, @@ -51,17 +51,20 @@ void SketcherPrs_Perpendicular::Compute(const Handle(PrsMgr_PresentationManager3 { prepareAspect(); - std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); + + std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(aObj1); if (aLine1.get() == NULL) return; - std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B()); + std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(aObj2); if (aLine2.get() == NULL) return; SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); - gp_Pnt aP1 = aMgr->getPosition(aLine1, this); - gp_Pnt aP2 = aMgr->getPosition(aLine2, this); + gp_Pnt aP1 = aMgr->getPosition(aObj1, this); + gp_Pnt aP2 = aMgr->getPosition(aObj2, this); Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); aGroup->SetPrimitivesAspect(myAspect); diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp index 5237b18e2..36c5a72b2 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -5,6 +5,7 @@ // Author: Vitaly SMETANNIKOV #include "SketcherPrs_PositionMgr.h" +#include "SketcherPrs_Tools.h" #include @@ -25,7 +26,7 @@ SketcherPrs_PositionMgr::SketcherPrs_PositionMgr() } -int SketcherPrs_PositionMgr::getPositionIndex(std::shared_ptr theLine, +int SketcherPrs_PositionMgr::getPositionIndex(ObjectPtr theLine, Handle(SketcherPrs_SymbolPrs) thePrs) { if (myShapes.count(theLine) == 1) { @@ -45,11 +46,12 @@ int SketcherPrs_PositionMgr::getPositionIndex(std::shared_ptr the } } -gp_Pnt SketcherPrs_PositionMgr::getPosition(std::shared_ptr theLine, +gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theLine, Handle(SketcherPrs_SymbolPrs) thePrs) { + std::shared_ptr aShape = SketcherPrs_Tools::getLine(theLine); std::shared_ptr aEdge = - std::shared_ptr(new GeomAPI_Edge(theLine)); + std::shared_ptr(new GeomAPI_Edge(aShape)); std::shared_ptr aPnt1 = aEdge->firstPoint(); std::shared_ptr aPnt2 = aEdge->lastPoint(); @@ -96,7 +98,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(std::shared_ptr theLi void SketcherPrs_PositionMgr::deleteConstraint(Handle(SketcherPrs_SymbolPrs) thePrs) { - std::map, PositionsMap>::iterator aIt; + std::map::iterator aIt; for (aIt = myShapes.begin(); aIt != myShapes.end(); ++aIt) { PositionsMap& aPosMap = aIt->second; if (aPosMap.count(thePrs.Access()) > 0) diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.h b/src/SketcherPrs/SketcherPrs_PositionMgr.h index 8c8445de8..65a2aa068 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.h +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.h @@ -11,6 +11,7 @@ #include #include +#include #include @@ -28,7 +29,7 @@ public: /// Returns position of symbol for the given presentation /// \param theLine constrained object /// \param thePrs a presentation of constraint - gp_Pnt getPosition(std::shared_ptr theLine, Handle(SketcherPrs_SymbolPrs) thePrs); + gp_Pnt getPosition(ObjectPtr theLine, Handle(SketcherPrs_SymbolPrs) thePrs); /// Deletes constraint object from internal structures. Has to be called on constraint delete. /// \param thePrs a constraint presentation @@ -41,7 +42,7 @@ private: /// Returns position index of the given constraint /// \param theLine constrained object /// \param thePrs a presentation of constraint - int getPositionIndex(std::shared_ptr theLine, Handle(SketcherPrs_SymbolPrs) thePrs); + int getPositionIndex(ObjectPtr theLine, Handle(SketcherPrs_SymbolPrs) thePrs); private: typedef std::map PositionsMap; @@ -50,7 +51,7 @@ private: PositionsMap myIndexes; /// The map contains position index - std::map, PositionsMap> myShapes; + std::map myShapes; }; #endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_Rigid.cpp b/src/SketcherPrs/SketcherPrs_Rigid.cpp index e171bf80c..099096c20 100644 --- a/src/SketcherPrs/SketcherPrs_Rigid.cpp +++ b/src/SketcherPrs/SketcherPrs_Rigid.cpp @@ -55,12 +55,13 @@ void SketcherPrs_Rigid::Compute(const Handle(PrsMgr_PresentationManager3d)& theP { prepareAspect(); - std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(aObj1); if (aLine1.get() == NULL) return; SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); - gp_Pnt aP1 = aMgr->getPosition(aLine1, this); + gp_Pnt aP1 = aMgr->getPosition(aObj1, this); Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); aGroup->SetPrimitivesAspect(myAspect); diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp index fe06620a3..9e051971a 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp @@ -70,7 +70,8 @@ void SketcherPrs_SymbolPrs::prepareAspect() void SketcherPrs_SymbolPrs::addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const { - std::shared_ptr aLine = SketcherPrs_Tools::getLine(myConstraint, theAttrName); + ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, theAttrName); + std::shared_ptr aLine = SketcherPrs_Tools::getLine(aObj); if (aLine.get() == NULL) return; std::shared_ptr aEdge = std::shared_ptr(new GeomAPI_Edge(aLine)); diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index 5f109ca4d..e92283e42 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -17,16 +17,19 @@ namespace SketcherPrs_Tools { - -std::shared_ptr getLine(SketchPlugin_Constraint* theFeature, - const std::string& theAttrName) +ObjectPtr getResult(SketchPlugin_Constraint* theFeature, const std::string& theAttrName) { std::shared_ptr aData = theFeature->data(); std::shared_ptr anAttr = std::dynamic_pointer_cast(aData->attribute(theAttrName)); - ObjectPtr aObject = anAttr->object(); - ResultConstructionPtr aRes = std::dynamic_pointer_cast(aObject); + return anAttr->object(); +} + + +std::shared_ptr getLine(ObjectPtr theObject) +{ + ResultConstructionPtr aRes = std::dynamic_pointer_cast(theObject); if (aRes.get() != NULL) { return aRes->shape(); } diff --git a/src/SketcherPrs/SketcherPrs_Tools.h b/src/SketcherPrs/SketcherPrs_Tools.h index ac779d38e..e913a2fd6 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.h +++ b/src/SketcherPrs/SketcherPrs_Tools.h @@ -10,14 +10,17 @@ #include "SketcherPrs.h" #include #include +#include #include class SketchPlugin_Constraint; namespace SketcherPrs_Tools { - std::shared_ptr getLine(SketchPlugin_Constraint* theFeature, - const std::string& theAttrName); + ObjectPtr getResult(SketchPlugin_Constraint* theFeature, + const std::string& theAttrName); + + std::shared_ptr getLine(ObjectPtr theObject); std::shared_ptr getPoint(SketchPlugin_Constraint* theFeature, const std::string& theAttrName);