]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_Transformation.cpp
Salome HOME
Remove extra files
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Transformation.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Transformation.cpp
4 // Created:     16 February 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Transformation.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
10
11 #include <SketchPlugin_Constraint.h>
12 #include <SketchPlugin_MultiTranslation.h>
13 #include <SketchPlugin_MultiRotation.h>
14 #include <ModelAPI_AttributeRefList.h>
15 #include <GeomDataAPI_Point2D.h>
16
17 #include <Graphic3d_AspectLine3d.hxx>
18 #include <Prs3d_Root.hxx>
19 #include <Prs3d_LineAspect.hxx>
20 #include <Geom_CartesianPoint.hxx>
21 #include <gp_Pnt.hxx>
22 #include <StdPrs_Point.hxx>
23
24
25
26 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
27 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
28
29 static Handle(Image_AlienPixMap) MyPixMap;
30
31 SketcherPrs_Transformation::SketcherPrs_Transformation(ModelAPI_Feature* theConstraint, 
32                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane,
33                                            bool isTranslation) 
34  : SketcherPrs_SymbolPrs(theConstraint, thePlane), myIsTranslation(isTranslation)
35 {
36 }  
37
38 bool SketcherPrs_Transformation::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
39                                                   const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
40 {
41   bool aReadyToDisplay = false;
42
43   std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
44   // Get transformated objects list
45   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = 
46     aData->reflist(SketchPlugin_Constraint::ENTITY_B());
47   if (anAttrB.get() == NULL)
48     return aReadyToDisplay;
49
50   int aNbB = anAttrB->size();
51   aReadyToDisplay = aNbB > 0;
52
53 #ifdef DEBUG_HIDE_COPY_ATTRIBUTE
54   // additional check
55   if (theConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) {
56     // If it is translation
57     AttributePoint2DPtr aStart = GeomDataAPI_Point2D::getPoint2D(aData,
58                                             SketchPlugin_MultiTranslation::START_POINT_ID());
59     AttributePoint2DPtr aEnd = GeomDataAPI_Point2D::getPoint2D(aData,
60                                             SketchPlugin_MultiTranslation::END_POINT_ID());
61
62     aReadyToDisplay = 
63       aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized();
64   }
65   else if (theConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
66     // if it is rotation
67     AttributePoint2DPtr aCenter = 
68       GeomDataAPI_Point2D::getPoint2D(aData, SketchPlugin_MultiRotation::CENTER_ID());
69     aReadyToDisplay = aCenter.get() && aCenter->isInitialized();
70   }
71 #endif
72   return aReadyToDisplay;
73 }
74
75 bool SketcherPrs_Transformation::updateIfReadyToDisplay(double theStep) const 
76 {
77   if (!IsReadyToDisplay(myConstraint, myPlane))
78     return false;
79
80   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
81   // Get transformated objects list
82   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
83     aData->reflist(SketchPlugin_Constraint::ENTITY_B());
84
85   int aNbB = anAttrB->size();
86   if (aNbB == 0)
87   {
88 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
89   //if (!myPntArray.IsNull())
90     //  mySPoints.Clear();
91 #endif
92   }
93
94   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
95   myPntArray = new Graphic3d_ArrayOfPoints(aNbB);
96
97   int i;
98   ObjectPtr aObj;
99   gp_Pnt aP1;
100   // Compute points of symbols
101   for (i = 0; i < aNbB; i++) {
102     aObj = anAttrB->object(i);
103     if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
104       continue;
105     aP1 = aMgr->getPosition(aObj, this, theStep);
106     myPntArray->SetVertice(i + 1, aP1);
107   }  
108
109   return true;
110 }
111
112 void SketcherPrs_Transformation::drawLines(const Handle(Prs3d_Presentation)& thePrs, 
113                                            Quantity_Color theColor) const
114 {
115   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
116   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = 
117     aData->reflist(SketchPlugin_Constraint::ENTITY_B());
118   if (anAttrB.get() == NULL)
119     return;
120
121   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
122
123   // drawListOfShapes uses myDrawer for attributes definition
124   Handle(Prs3d_LineAspect) aLnAspect = new Prs3d_LineAspect(theColor, Aspect_TOL_SOLID, 1);
125   myDrawer->SetLineAspect(aLnAspect);
126
127   drawListOfShapes(anAttrB, thePrs);
128   if (myConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) {
129     // If it is translation
130     AttributePoint2DPtr aStart = GeomDataAPI_Point2D::getPoint2D(aData,
131                                             SketchPlugin_MultiTranslation::START_POINT_ID());
132     AttributePoint2DPtr aEnd = GeomDataAPI_Point2D::getPoint2D(aData,
133                                             SketchPlugin_MultiTranslation::END_POINT_ID());
134
135     if (aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized()) {
136       // Add start point
137       std::shared_ptr<GeomAPI_Pnt> aPnt = myPlane->to3D(aStart->x(), aStart->y());
138       Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
139       StdPrs_Point::Add(thePrs, aPoint, myDrawer);
140
141       // Add end point
142       aPnt = myPlane->to3D(aEnd->x(), aEnd->y());
143       aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
144       StdPrs_Point::Add(thePrs, aPoint, myDrawer);
145     }
146   } else if (myConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
147     // if it is rotation
148     AttributePoint2DPtr aCenter =
149       GeomDataAPI_Point2D::getPoint2D(aData, SketchPlugin_MultiRotation::CENTER_ID());
150     if (aCenter.get() && aCenter->isInitialized()) {
151       // Show center of rotation
152       std::shared_ptr<GeomAPI_Pnt> aPnt = myPlane->to3D(aCenter->x(), aCenter->y());
153       Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
154       StdPrs_Point::Add(thePrs, aPoint, myDrawer);
155     }
156   }
157 }
158