]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Position manager created
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 13 Mar 2015 15:54:50 +0000 (18:54 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 13 Mar 2015 15:54:50 +0000 (18:54 +0300)
src/SketcherPrs/CMakeLists.txt
src/SketcherPrs/SketcherPrs_Parallel.cpp
src/SketcherPrs/SketcherPrs_Perpendicular.cpp
src/SketcherPrs/SketcherPrs_PositionMgr.cpp [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_PositionMgr.h [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_SymbolPrs.cpp
src/SketcherPrs/SketcherPrs_SymbolPrs.h
src/SketcherPrs/SketcherPrs_Tools.cpp
src/SketcherPrs/SketcherPrs_Tools.h

index 7b2fd3f706bc67a09417c6e03b15ae224ab7da68..37ec076c998cbe65ced1588045c750e75ac4d363 100644 (file)
@@ -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
index 9cb425b46643b37465ffd5985f1c990c9d0061f9..e34dfb49696b8a70f4d73c91c260b0e7f71b8311 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "SketcherPrs_Parallel.h"
 #include "SketcherPrs_Tools.h"
+#include "SketcherPrs_PositionMgr.h"
 
 #include <GeomAPI_Pnt.h>
 
@@ -55,37 +56,17 @@ void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& t
 {
   prepareAspect();
 
-  std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+  std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
   if (aLine1.get() == NULL)
     return;
 
-  std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+  std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
   if (aLine2.get() == NULL)
     return;
 
-  std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLine1->firstPoint();
-  std::shared_ptr<GeomAPI_Pnt> 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<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
-  gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
-  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<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
-  aShift = aVec2.Crossed(myPlane->norm()->impl<gp_Dir>());
-  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);
index 1d20021b3089a161123e6626107629e87c6cd19b..05c7506b251198b26d8cabcf13dfb0510160a9bb 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "SketcherPrs_Perpendicular.h"
 #include "SketcherPrs_Tools.h"
+#include "SketcherPrs_PositionMgr.h"
 
 #include <GeomAPI_Pnt.h>
 
@@ -57,37 +58,40 @@ void SketcherPrs_Perpendicular::Compute(const Handle(PrsMgr_PresentationManager3
 {
   prepareAspect();
 
-  std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+  std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
   if (aLine1.get() == NULL)
     return;
 
-  std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+  std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
   if (aLine2.get() == NULL)
     return;
 
-  std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLine1->firstPoint();
-  std::shared_ptr<GeomAPI_Pnt> 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<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
-  gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
-  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<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
-  aShift = aVec2.Crossed(myPlane->norm()->impl<gp_Dir>());
-  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<GeomAPI_Pnt> aPnt1 = aLine1->firstPoint();
+  //std::shared_ptr<GeomAPI_Pnt> 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<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
+  //gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
+  //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<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
+  //aShift = aVec2.Crossed(myPlane->norm()->impl<gp_Dir>());
+  //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 (file)
index 0000000..5237b18
--- /dev/null
@@ -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 <GeomAPI_Edge.h>
+
+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<GeomAPI_Shape> 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<GeomAPI_Shape> theLine, 
+                                            Handle(SketcherPrs_SymbolPrs) thePrs)
+{
+  std::shared_ptr<GeomAPI_Edge> aEdge = 
+    std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(theLine));
+
+  std::shared_ptr<GeomAPI_Pnt> aPnt1 = aEdge->firstPoint();
+  std::shared_ptr<GeomAPI_Pnt> 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<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
+  gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl<gp_Dir>());
+  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<std::shared_ptr<GeomAPI_Shape>, 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 (file)
index 0000000..8c8445d
--- /dev/null
@@ -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 <GeomAPI_Shape.h>
+#include <gp_Pnt.hxx>
+
+#include <map>
+
+/**
+* \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<GeomAPI_Shape> 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<GeomAPI_Shape> theLine, Handle(SketcherPrs_SymbolPrs) thePrs);
+
+private:
+  typedef std::map<void*, int> PositionsMap;
+
+  /// The map which contains position of presentation
+  PositionsMap myIndexes;
+
+  /// The map contains position index 
+  std::map<std::shared_ptr<GeomAPI_Shape>, PositionsMap> myShapes;
+};
+
+#endif
\ No newline at end of file
index 144664122a2f66c548dff867b47b31c527912322..4637f910c08de6a27b2efe79b863997c73aff634 100644 (file)
@@ -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<GeomAPI_Edge> aLine = SketcherPrs_Tools::getLine(myConstraint, theAttrName);
+  std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getLine(myConstraint, theAttrName);
   if (aLine.get() == NULL)
     return;
+  std::shared_ptr<GeomAPI_Edge> aEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLine));
 
-  std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLine->firstPoint();
-  std::shared_ptr<GeomAPI_Pnt> aPnt2 = aLine->lastPoint();
+  std::shared_ptr<GeomAPI_Pnt> aPnt1 = aEdge->firstPoint();
+  std::shared_ptr<GeomAPI_Pnt> aPnt2 = aEdge->lastPoint();
 
   Handle(Graphic3d_ArrayOfSegments) aLines = new Graphic3d_ArrayOfSegments(2, 1);
   aLines->AddVertex(aPnt1->impl<gp_Pnt>());
index 792fde0155d82c6d4d4a0bd6e7e9b3784190761e..6cce9503e6e7bdc97b27fc3ca0913ed4142fa7f6 100644 (file)
@@ -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<GeomAPI_Ax3>& 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<GeomAPI_Ax3> plane() const { return myPlane; }
+
+  Standard_EXPORT SketchPlugin_Constraint* feature() const { return myConstraint; }
+
   DEFINE_STANDARD_RTTI(SketcherPrs_SymbolPrs)
 
 protected:
index 2f356e16b756122862c8d44a581ea064a4da07d3..5f109ca4d4236923ce24f2d4f97f25e0834c8157 100644 (file)
@@ -18,7 +18,7 @@
 namespace SketcherPrs_Tools {
 
 
-std::shared_ptr<GeomAPI_Edge> getLine(SketchPlugin_Constraint* theFeature,
+std::shared_ptr<GeomAPI_Shape> getLine(SketchPlugin_Constraint* theFeature,
                                       const std::string& theAttrName)
 {
   std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
@@ -28,12 +28,9 @@ std::shared_ptr<GeomAPI_Edge> getLine(SketchPlugin_Constraint* theFeature,
   ObjectPtr aObject = anAttr->object();
   ResultConstructionPtr aRes = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObject);
   if (aRes.get() != NULL) {
-    std::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
-    if (aShape.get() != NULL) {   
-      return std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aShape));
-    }
+    return aRes->shape();
   }
-  return std::shared_ptr<GeomAPI_Edge>();
+  return std::shared_ptr<GeomAPI_Shape>();
 }
 
 
index 5a932956044589e7e6194be81e4eb42d59167d82..ac779d38e6cf8d3d02f2c02de79e610d64fd0351 100644 (file)
@@ -8,7 +8,7 @@
 #define SketcherPrs_Tools_H
 
 #include "SketcherPrs.h"
-#include <GeomAPI_Edge.h>
+#include <GeomAPI_Shape.h>
 #include <GeomAPI_Pnt2d.h>
 #include <string>
 
@@ -16,7 +16,7 @@ class SketchPlugin_Constraint;
 
 namespace SketcherPrs_Tools {
 
-  std::shared_ptr<GeomAPI_Edge> getLine(SketchPlugin_Constraint* theFeature,
+  std::shared_ptr<GeomAPI_Shape> getLine(SketchPlugin_Constraint* theFeature,
                                         const std::string& theAttrName);
 
   std::shared_ptr<GeomAPI_Pnt2d> getPoint(SketchPlugin_Constraint* theFeature,