From: vsv Date: Fri, 13 Mar 2015 15:54:50 +0000 (+0300) Subject: Position manager created X-Git-Tag: V_1.1.0~134^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=71862c3b2c0e78ef927520985f68c5ffa2916b78;p=modules%2Fshaper.git Position manager created --- diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt index 7b2fd3f70..37ec076c9 100644 --- a/src/SketcherPrs/CMakeLists.txt +++ b/src/SketcherPrs/CMakeLists.txt @@ -8,6 +8,7 @@ SET(PROJECT_HEADERS SketcherPrs_Tools.h SketcherPrs_Perpendicular.h SketcherPrs_SymbolPrs.h + SketcherPrs_PositionMgr.h ) SET(PROJECT_SOURCES @@ -17,6 +18,7 @@ SET(PROJECT_SOURCES SketcherPrs_Tools.cpp SketcherPrs_Perpendicular.cpp SketcherPrs_SymbolPrs.cpp + SketcherPrs_PositionMgr.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/SketcherPrs/SketcherPrs_Parallel.cpp b/src/SketcherPrs/SketcherPrs_Parallel.cpp index 9cb425b46..e34dfb496 100644 --- a/src/SketcherPrs/SketcherPrs_Parallel.cpp +++ b/src/SketcherPrs/SketcherPrs_Parallel.cpp @@ -6,6 +6,7 @@ #include "SketcherPrs_Parallel.h" #include "SketcherPrs_Tools.h" +#include "SketcherPrs_PositionMgr.h" #include @@ -55,37 +56,17 @@ void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& t { prepareAspect(); - std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A()); if (aLine1.get() == NULL) return; - std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B()); + std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B()); if (aLine2.get() == NULL) return; - std::shared_ptr aPnt1 = aLine1->firstPoint(); - std::shared_ptr aPnt2 = aLine1->lastPoint(); - gp_Pnt aP1((aPnt1->x() + aPnt2->x())/2., - (aPnt1->y() + aPnt2->y())/2., - (aPnt1->z() + aPnt2->z())/2.); - - gp_Vec aVec1(aPnt1->impl(), aPnt2->impl()); - gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl()); - aShift.Normalize(); - aShift.Multiply(20); - aP1.Translate(aShift); - - aPnt1 = aLine2->firstPoint(); - aPnt2 = aLine2->lastPoint(); - gp_Pnt aP2((aPnt1->x() + aPnt2->x())/2., - (aPnt1->y() + aPnt2->y())/2., - (aPnt1->z() + aPnt2->z())/2.); - - gp_Vec aVec2(aPnt1->impl(), aPnt2->impl()); - aShift = aVec2.Crossed(myPlane->norm()->impl()); - aShift.Normalize(); - aShift.Multiply(20); - aP2.Translate(aShift); + SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); + gp_Pnt aP1 = aMgr->getPosition(aLine1, this); + gp_Pnt aP2 = aMgr->getPosition(aLine2, 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 1d20021b3..05c7506b2 100644 --- a/src/SketcherPrs/SketcherPrs_Perpendicular.cpp +++ b/src/SketcherPrs/SketcherPrs_Perpendicular.cpp @@ -6,6 +6,7 @@ #include "SketcherPrs_Perpendicular.h" #include "SketcherPrs_Tools.h" +#include "SketcherPrs_PositionMgr.h" #include @@ -57,37 +58,40 @@ void SketcherPrs_Perpendicular::Compute(const Handle(PrsMgr_PresentationManager3 { prepareAspect(); - std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A()); + std::shared_ptr aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A()); if (aLine1.get() == NULL) return; - std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B()); + std::shared_ptr aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B()); if (aLine2.get() == NULL) return; - std::shared_ptr aPnt1 = aLine1->firstPoint(); - std::shared_ptr aPnt2 = aLine1->lastPoint(); - gp_Pnt aP1((aPnt1->x() + aPnt2->x())/2., - (aPnt1->y() + aPnt2->y())/2., - (aPnt1->z() + aPnt2->z())/2.); - - gp_Vec aVec1(aPnt1->impl(), aPnt2->impl()); - gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl()); - aShift.Normalize(); - aShift.Multiply(20); - aP1.Translate(aShift); - - aPnt1 = aLine2->firstPoint(); - aPnt2 = aLine2->lastPoint(); - gp_Pnt aP2((aPnt1->x() + aPnt2->x())/2., - (aPnt1->y() + aPnt2->y())/2., - (aPnt1->z() + aPnt2->z())/2.); - - gp_Vec aVec2(aPnt1->impl(), aPnt2->impl()); - aShift = aVec2.Crossed(myPlane->norm()->impl()); - aShift.Normalize(); - aShift.Multiply(20); - aP2.Translate(aShift); + SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); + gp_Pnt aP1 = aMgr->getPosition(aLine1, this); + gp_Pnt aP2 = aMgr->getPosition(aLine2, this); + //std::shared_ptr aPnt1 = aLine1->firstPoint(); + //std::shared_ptr aPnt2 = aLine1->lastPoint(); + //gp_Pnt aP1((aPnt1->x() + aPnt2->x())/2., + // (aPnt1->y() + aPnt2->y())/2., + // (aPnt1->z() + aPnt2->z())/2.); + + //gp_Vec aVec1(aPnt1->impl(), aPnt2->impl()); + //gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl()); + //aShift.Normalize(); + //aShift.Multiply(20); + //aP1.Translate(aShift); + + //aPnt1 = aLine2->firstPoint(); + //aPnt2 = aLine2->lastPoint(); + //gp_Pnt aP2((aPnt1->x() + aPnt2->x())/2., + // (aPnt1->y() + aPnt2->y())/2., + // (aPnt1->z() + aPnt2->z())/2.); + + //gp_Vec aVec2(aPnt1->impl(), aPnt2->impl()); + //aShift = aVec2.Crossed(myPlane->norm()->impl()); + //aShift.Normalize(); + //aShift.Multiply(20); + //aP2.Translate(aShift); 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 new file mode 100644 index 000000000..5237b18e2 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -0,0 +1,111 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_PositionMgr.cpp +// Created: 13 March 2015 +// Author: Vitaly SMETANNIKOV + +#include "SketcherPrs_PositionMgr.h" + +#include + +static const int MyStep = 20; + +static SketcherPrs_PositionMgr* MyPosMgr = NULL; + + +SketcherPrs_PositionMgr* SketcherPrs_PositionMgr::get() +{ + if (MyPosMgr == NULL) + MyPosMgr = new SketcherPrs_PositionMgr(); + return MyPosMgr; +} + +SketcherPrs_PositionMgr::SketcherPrs_PositionMgr() +{ +} + + +int SketcherPrs_PositionMgr::getPositionIndex(std::shared_ptr theLine, + Handle(SketcherPrs_SymbolPrs) thePrs) +{ + if (myShapes.count(theLine) == 1) { + PositionsMap& aPosMap = myShapes[theLine]; + if (aPosMap.count(thePrs.Access()) == 1) { + return aPosMap[thePrs.Access()]; + } else { + int aInd = aPosMap.size(); + aPosMap[thePrs.Access()] = aInd; + return aInd; + } + } else { + PositionsMap aPosMap; + aPosMap[thePrs.Access()] = 0; + myShapes[theLine] = aPosMap; + return 0; + } +} + +gp_Pnt SketcherPrs_PositionMgr::getPosition(std::shared_ptr theLine, + Handle(SketcherPrs_SymbolPrs) thePrs) +{ + std::shared_ptr aEdge = + std::shared_ptr(new GeomAPI_Edge(theLine)); + + std::shared_ptr aPnt1 = aEdge->firstPoint(); + std::shared_ptr aPnt2 = aEdge->lastPoint(); + + // Find the middle point + gp_Pnt aP((aPnt1->x() + aPnt2->x())/2., + (aPnt1->y() + aPnt2->y())/2., + (aPnt1->z() + aPnt2->z())/2.); + + gp_Vec aVec1(aPnt1->impl(), aPnt2->impl()); + gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl()); + aShift.Normalize(); + aShift.Multiply(MyStep); + + int aPos = getPositionIndex(theLine, thePrs); + int aM = 1; + if ((aPos % 2) == 0) { + // Even position + aP.Translate(aShift); + if (aPos > 0) { + if (aPos % 4 == 0) + aM = aPos / 4; + else + aM = -(aPos + 2) / 4; + } + } else { + // Odd position + aP.Translate(-aShift); + if (aPos > 1) { + if (aPos % 4 == 0) + aM = (aPos - 1) / 4; + else + aM = -(aPos + 1) / 4; + } + } + if (aPos > 1) { + // Normalize vector along the line + aVec1.Normalize(); + aVec1.Multiply(MyStep); + aP.Translate(aVec1.Multiplied(aM)); + } + return aP; +} + +void SketcherPrs_PositionMgr::deleteConstraint(Handle(SketcherPrs_SymbolPrs) thePrs) +{ + std::map, PositionsMap>::iterator aIt; + for (aIt = myShapes.begin(); aIt != myShapes.end(); ++aIt) { + PositionsMap& aPosMap = aIt->second; + if (aPosMap.count(thePrs.Access()) > 0) + aPosMap.erase(aPosMap.find(thePrs.Access())); + } + for (aIt = myShapes.begin(); aIt != myShapes.end(); ++aIt) { + if (aIt->second.size() == 0) { + myShapes.erase(aIt); + aIt = myShapes.begin(); + } + } +} diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.h b/src/SketcherPrs/SketcherPrs_PositionMgr.h new file mode 100644 index 000000000..8c8445de8 --- /dev/null +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.h @@ -0,0 +1,56 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketcherPrs_PositionMgr.h +// Created: 13 March 2015 +// Author: Vitaly SMETANNIKOV + +#ifndef SketcherPrs_PositionMgr_H +#define SketcherPrs_PositionMgr_H + +#include "SketcherPrs_SymbolPrs.h" + +#include +#include + +#include + +/** +* \ingroup GUI +* A class Position Manager which manages position of constraints symbols along a source object line. +* it expects that symbol icons have size 16x16 px +*/ +class SketcherPrs_PositionMgr +{ +public: + /// Returns current instance of position manager + static SketcherPrs_PositionMgr* get(); + + /// 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); + + /// Deletes constraint object from internal structures. Has to be called on constraint delete. + /// \param thePrs a constraint presentation + void deleteConstraint(Handle(SketcherPrs_SymbolPrs) thePrs); + +private: + /// Constructor + SketcherPrs_PositionMgr(); + + /// 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); + +private: + typedef std::map PositionsMap; + + /// The map which contains position of presentation + PositionsMap myIndexes; + + /// The map contains position index + std::map, PositionsMap> myShapes; +}; + +#endif \ No newline at end of file diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp index 144664122..4637f910c 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp @@ -32,6 +32,7 @@ SketcherPrs_SymbolPrs::SketcherPrs_SymbolPrs(SketchPlugin_Constraint* theConstra SetAutoHilight(Standard_False); } + Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon() { if (myIconsMap.count(iconName()) == 1) { @@ -65,12 +66,13 @@ 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); + std::shared_ptr aLine = SketcherPrs_Tools::getLine(myConstraint, theAttrName); if (aLine.get() == NULL) return; + std::shared_ptr aEdge = std::shared_ptr(new GeomAPI_Edge(aLine)); - std::shared_ptr aPnt1 = aLine->firstPoint(); - std::shared_ptr aPnt2 = aLine->lastPoint(); + std::shared_ptr aPnt1 = aEdge->firstPoint(); + std::shared_ptr aPnt2 = aEdge->lastPoint(); Handle(Graphic3d_ArrayOfSegments) aLines = new Graphic3d_ArrayOfSegments(2, 1); aLines->AddVertex(aPnt1->impl()); diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.h b/src/SketcherPrs/SketcherPrs_SymbolPrs.h index 792fde015..6cce9503e 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.h +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.h @@ -31,13 +31,17 @@ public: /// Constructor /// \param theConstraint a constraint feature /// \param thePlane a coordinate plane of current sketch - SketcherPrs_SymbolPrs(SketchPlugin_Constraint* theConstraint, + Standard_EXPORT SketcherPrs_SymbolPrs(SketchPlugin_Constraint* theConstraint, const std::shared_ptr& thePlane); - + //! Method which clear all selected owners belonging //! to this selectable object ( for fast presentation draw ) Standard_EXPORT virtual void ClearSelected(); + Standard_EXPORT std::shared_ptr plane() const { return myPlane; } + + Standard_EXPORT SketchPlugin_Constraint* feature() const { return myConstraint; } + DEFINE_STANDARD_RTTI(SketcherPrs_SymbolPrs) protected: diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index 2f356e16b..5f109ca4d 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -18,7 +18,7 @@ namespace SketcherPrs_Tools { -std::shared_ptr getLine(SketchPlugin_Constraint* theFeature, +std::shared_ptr getLine(SketchPlugin_Constraint* theFeature, const std::string& theAttrName) { std::shared_ptr aData = theFeature->data(); @@ -28,12 +28,9 @@ std::shared_ptr getLine(SketchPlugin_Constraint* theFeature, ObjectPtr aObject = anAttr->object(); ResultConstructionPtr aRes = std::dynamic_pointer_cast(aObject); if (aRes.get() != NULL) { - std::shared_ptr aShape = aRes->shape(); - if (aShape.get() != NULL) { - return std::shared_ptr(new GeomAPI_Edge(aShape)); - } + return aRes->shape(); } - return std::shared_ptr(); + return std::shared_ptr(); } diff --git a/src/SketcherPrs/SketcherPrs_Tools.h b/src/SketcherPrs/SketcherPrs_Tools.h index 5a9329560..ac779d38e 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.h +++ b/src/SketcherPrs/SketcherPrs_Tools.h @@ -8,7 +8,7 @@ #define SketcherPrs_Tools_H #include "SketcherPrs.h" -#include +#include #include #include @@ -16,7 +16,7 @@ class SketchPlugin_Constraint; namespace SketcherPrs_Tools { - std::shared_ptr getLine(SketchPlugin_Constraint* theFeature, + std::shared_ptr getLine(SketchPlugin_Constraint* theFeature, const std::string& theAttrName); std::shared_ptr getPoint(SketchPlugin_Constraint* theFeature,