Salome HOME
Create mirror symbols
[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 <ModelAPI_AttributeRefList.h>
14
15 #include <Graphic3d_AspectLine3d.hxx>
16 #include <Prs3d_Root.hxx>
17
18
19
20 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Mirror, SketcherPrs_SymbolPrs);
21 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Mirror, SketcherPrs_SymbolPrs);
22
23 static Handle(Image_AlienPixMap) MyPixMap;
24
25 SketcherPrs_Mirror::SketcherPrs_Mirror(ModelAPI_Feature* theConstraint, 
26                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
27  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
28 {
29 }  
30
31
32 bool SketcherPrs_Mirror::updatePoints(double theStep) const
33 {
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   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
40   if (anAttrB.get() == NULL)
41     return false;
42   std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
43   if (anAttrC.get() == NULL)
44     return false;
45
46   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
47   int aNb = anAttrB->size();
48   if (aNb != anAttrC->size())
49     return false;
50
51   myPntArray = new Graphic3d_ArrayOfPoints(2 * aNb);
52   int i;
53   ObjectPtr aObj;
54   gp_Pnt aP1;
55   for (i = 0; i < aNb; i++) {
56     aObj = anAttrB->object(i);
57     aP1 = aMgr->getPosition(aObj, this, theStep);
58     myPntArray->SetVertice(i + 1, aP1);
59   }  
60   for (i = 0; i < aNb; i++) {
61     aObj = anAttrC->object(i);
62     aP1 = aMgr->getPosition(aObj, this, theStep);
63     myPntArray->SetVertice(aNb + i + 1, aP1);
64   }  
65   return true;
66 }
67
68
69 void SketcherPrs_Mirror::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
70 {
71   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
72   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
73   if (anAttrB.get() == NULL)
74     return;
75   std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
76   if (anAttrC.get() == NULL)
77     return;
78
79   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
80   int aNb = anAttrB->size();
81   if (aNb != anAttrC->size())
82     return;
83
84   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
85
86   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
87   aGroup->SetPrimitivesAspect(aLineAspect);
88
89   // Draw axis line
90   addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
91
92   // Draw source objects
93   int i;
94   ObjectPtr aObj;
95   for (i = 0; i < aNb; i++) {
96     aObj = anAttrB->object(i);
97     std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
98     if (aShape.get() != NULL)
99       drawShape(aShape, thePrs);
100   }
101   // draw mirrored objects
102   for (i = 0; i < aNb; i++) {
103     aObj = anAttrC->object(i);
104     std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
105     if (aShape.get() != NULL)
106       drawShape(aShape, thePrs);
107   }
108 }
109