Salome HOME
Prepare version 1.2.1: quick fix for iteration 2 release
[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 <AIS_Drawer.hxx>
21 #include <gp_Pnt2d.hxx>
22
23 #include <Graphic3d_AspectLine3d.hxx>
24 #include <Prs3d_Root.hxx>
25
26 #include <GeomAdaptor_Curve.hxx>
27 #include <BRep_Tool.hxx>
28 #include <StdPrs_DeflectionCurve.hxx>
29 #include <StdPrs_Point.hxx>
30 #include <Geom_CartesianPoint.hxx>
31
32
33
34 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Rigid, SketcherPrs_SymbolPrs);
35 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Rigid, SketcherPrs_SymbolPrs);
36
37 static Handle(Image_AlienPixMap) MyPixMap; 
38
39
40
41 SketcherPrs_Rigid::SketcherPrs_Rigid(ModelAPI_Feature* theConstraint, 
42                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
43  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
44 {
45   myPntArray = new Graphic3d_ArrayOfPoints(1);
46   myPntArray->AddVertex(0., 0., 0.);
47 }  
48
49
50 bool SketcherPrs_Rigid::updatePoints(double theStep) const 
51 {
52   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
53   std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = aData->refattr(SketchPlugin_Constraint::ENTITY_A());
54   AttributePtr aRefAttr = anAttr->attr();
55   if (anAttr->isObject()) {
56     ObjectPtr aObj = anAttr->object();
57     if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
58       return false;
59
60     SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
61     gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep);
62     myPntArray->SetVertice(1, aP1);
63   } else {
64     std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_A());
65     if (aPnt.get() == NULL)
66       return false;
67     std::shared_ptr<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y() + theStep);
68     myPntArray->SetVertice(1, aPoint->impl<gp_Pnt>());
69   }
70   return true;
71 }
72
73
74 void SketcherPrs_Rigid::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
75 {
76   ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
77   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
78   std::shared_ptr<GeomAPI_Shape> aShape;
79   if (aFeature.get()) {
80     const std::list<ResultPtr>& aResults = aFeature->results();
81     std::list<ResultPtr>::const_iterator aIt;
82     for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
83       aShape = (*aIt)->shape();
84       if (aShape->isEdge())
85         break;
86     }
87   } else {
88     aShape = SketcherPrs_Tools::getShape(aObj);
89   }
90   if (aShape.get() == NULL)
91     return;
92
93   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
94   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
95   aGroup->SetPrimitivesAspect(aLineAspect);
96
97   Handle(Prs3d_PointAspect) aPntAspect = new Prs3d_PointAspect(Aspect_TOM_PLUS, theColor, 1);
98   myDrawer->SetPointAspect(aPntAspect);
99   drawShape(aShape, thePrs);
100 }
101