]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_Rigid.cpp
Salome HOME
a430ef2c1728c28672fbe1e22a79d94481cbd5a5
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Rigid.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Rigid.cpp
4 // Created:     16 February 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Rigid.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
10
11 #include <GeomAPI_Pnt.h>
12 #include <GeomAPI_Edge.h>
13 #include <GeomAPI_Curve.h>
14 #include <GeomAPI_Vertex.h>
15
16 #include <ModelAPI_AttributeRefAttr.h>
17
18 #include <SketchPlugin_Constraint.h>
19
20 #include <gp_Pnt2d.hxx>
21
22 #include <Graphic3d_AspectLine3d.hxx>
23 #include <Prs3d_Root.hxx>
24
25 #include <GeomAdaptor_Curve.hxx>
26 #include <BRep_Tool.hxx>
27 #include <StdPrs_DeflectionCurve.hxx>
28 #include <StdPrs_Point.hxx>
29 #include <Geom_CartesianPoint.hxx>
30
31
32
33 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Rigid, SketcherPrs_SymbolPrs);
34
35 static Handle(Image_AlienPixMap) MyPixMap;
36
37
38
39 SketcherPrs_Rigid::SketcherPrs_Rigid(ModelAPI_Feature* theConstraint,
40                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane)
41  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
42 {
43 }
44
45 bool SketcherPrs_Rigid::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
46                                          const std::shared_ptr<GeomAPI_Ax3>& thePlane)
47 {
48   bool aReadyToDisplay = false;
49
50   std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
51   std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
52     aData->refattr(SketchPlugin_Constraint::ENTITY_A());
53   AttributePtr aRefAttr = anAttr->attr();
54   if (anAttr->isObject()) {
55     // The constraint attached to an object
56     ObjectPtr aObj = anAttr->object();
57     aReadyToDisplay =  SketcherPrs_Tools::getShape(aObj).get() != NULL;
58
59   } else {
60     // The constraint attached to a point
61     std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theConstraint,
62                                                    SketchPlugin_Constraint::ENTITY_A());
63     aReadyToDisplay = aPnt.get() != NULL;
64   }
65   return aReadyToDisplay;
66 }
67
68 bool SketcherPrs_Rigid::updateIfReadyToDisplay(double theStep) const
69 {
70   if (!IsReadyToDisplay(myConstraint, myPlane))
71     return false;
72
73   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
74   std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
75     aData->refattr(SketchPlugin_Constraint::ENTITY_A());
76   AttributePtr aRefAttr = anAttr->attr();
77   if (anAttr->isObject()) {
78     // The constraint attached to an object
79     ObjectPtr aObj = anAttr->object();
80
81     SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
82     gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep);
83     myPntArray->SetVertice(1, aP1);
84   } else {
85     // The constraint attached to a point
86     std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint,
87                                                   SketchPlugin_Constraint::ENTITY_A());
88     std::shared_ptr<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y() + theStep);
89     myPntArray->SetVertice(1, aPoint->impl<gp_Pnt>());
90   }
91   return true;
92 }
93
94
95 void SketcherPrs_Rigid::drawLines(const Handle(Prs3d_Presentation)& thePrs,
96                                   Quantity_Color theColor) const
97 {
98   ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
99   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
100   std::shared_ptr<GeomAPI_Shape> aShape;
101   if (aFeature.get()) {
102     // If constraint attached to a feature
103     const std::list<ResultPtr>& aResults = aFeature->results();
104     std::list<ResultPtr>::const_iterator aIt;
105     // Find a shape
106     for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
107       aShape = (*aIt)->shape();
108       if (aShape->isEdge())
109         break;
110     }
111   } else {
112     // Else it is a result
113     aShape = SketcherPrs_Tools::getShape(aObj);
114   }
115   if (aShape.get() == NULL)
116     return;
117
118   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
119   Handle(Graphic3d_AspectLine3d) aLineAspect =
120     new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
121   aGroup->SetPrimitivesAspect(aLineAspect);
122
123   Handle(Prs3d_PointAspect) aPntAspect = new Prs3d_PointAspect(Aspect_TOM_PLUS, theColor, 1);
124   myDrawer->SetPointAspect(aPntAspect);
125   drawShape(aShape, thePrs);
126 }
127