SketcherPrs_Tools.h
SketcherPrs_Perpendicular.h
SketcherPrs_SymbolPrs.h
+ SketcherPrs_PositionMgr.h
)
SET(PROJECT_SOURCES
SketcherPrs_Tools.cpp
SketcherPrs_Perpendicular.cpp
SketcherPrs_SymbolPrs.cpp
+ SketcherPrs_PositionMgr.cpp
)
SET(PROJECT_LIBRARIES
#include "SketcherPrs_Parallel.h"
#include "SketcherPrs_Tools.h"
+#include "SketcherPrs_PositionMgr.h"
#include <GeomAPI_Pnt.h>
{
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);
#include "SketcherPrs_Perpendicular.h"
#include "SketcherPrs_Tools.h"
+#include "SketcherPrs_PositionMgr.h"
#include <GeomAPI_Pnt.h>
{
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);
--- /dev/null
+// 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();
+ }
+ }
+}
--- /dev/null
+// 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
SetAutoHilight(Standard_False);
}
+
Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon()
{
if (myIconsMap.count(iconName()) == 1) {
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>());
/// 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:
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();
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>();
}
#define SketcherPrs_Tools_H
#include "SketcherPrs.h"
-#include <GeomAPI_Edge.h>
+#include <GeomAPI_Shape.h>
#include <GeomAPI_Pnt2d.h>
#include <string>
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,