Salome HOME
Merge branch 'python_parametric_api' of https://git.salome-platform.org/git/modules...
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Mirror.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Mirror.cpp
4 // Created:     6 April 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Mirror.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
10
11 #include <SketchPlugin_Constraint.h>
12
13 #include <Graphic3d_AspectLine3d.hxx>
14 #include <Prs3d_Root.hxx>
15 #include <Prs3d_LineAspect.hxx>
16
17
18
19 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Mirror, SketcherPrs_SymbolPrs);
20 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Mirror, SketcherPrs_SymbolPrs);
21
22 static Handle(Image_AlienPixMap) MyPixMap;
23
24 SketcherPrs_Mirror::SketcherPrs_Mirror(ModelAPI_Feature* theConstraint, 
25                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
26  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
27 {
28 }  
29
30
31 bool SketcherPrs_Mirror::updatePoints(double theStep) const
32 {
33   // Get axis of mirror
34   ObjectPtr aAxisObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
35   if (SketcherPrs_Tools::getShape(aAxisObj).get() == NULL)
36     return false;
37
38   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
39   // Get source objects
40   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
41   if (anAttrB.get() == NULL)
42     return false;
43   // Get mirrored objects
44   std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
45   if (anAttrC.get() == NULL)
46     return false;
47
48   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
49   int aNb = anAttrB->size();
50   // If size of source objects and mirrored ones is not equal then the constraint is not computed
51   if (aNb != anAttrC->size())
52     return false;
53
54   myPntArray = new Graphic3d_ArrayOfPoints(2 * aNb);
55   int i;
56   ObjectPtr aObj;
57   gp_Pnt aP1;
58   // get position for each source object
59   for (i = 0; i < aNb; i++) {
60     aObj = anAttrB->object(i);
61     aP1 = aMgr->getPosition(aObj, this, theStep);
62     myPntArray->SetVertice(i + 1, aP1);
63   }  
64   // Get position of each mirrored object
65   for (i = 0; i < aNb; i++) {
66     aObj = anAttrC->object(i);
67     aP1 = aMgr->getPosition(aObj, this, theStep);
68     myPntArray->SetVertice(aNb + i + 1, aP1);
69   }  
70   return true;
71 }
72
73
74 void SketcherPrs_Mirror::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
75 {
76   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
77   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
78   if (anAttrB.get() == NULL)
79     return;
80   std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
81   if (anAttrC.get() == NULL)
82     return;
83
84   int aNb = anAttrB->size();
85   if (aNb != anAttrC->size())
86     return;
87
88   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
89
90   // drawListOfShapes uses myDrawer for attributes definition
91   Handle(Prs3d_LineAspect) aLnAspect = new Prs3d_LineAspect(theColor, Aspect_TOL_SOLID, 1);
92   myDrawer->SetLineAspect(aLnAspect);
93
94   // Draw axis line
95   addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
96
97   // Draw source objects
98   drawListOfShapes(anAttrB, thePrs);
99
100   // draw mirrored objects
101   drawListOfShapes(anAttrC, thePrs);
102 }
103