]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_Transformation.cpp
Salome HOME
e4a4899ffef79ba0ba1ca34292bd270ac2d32994
[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 = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
46   if (anAttrB.get() == NULL)
47     return aReadyToDisplay;
48
49   int aNbB = anAttrB->size();
50   aReadyToDisplay = aNbB > 0;
51
52 #ifdef DEBUG_HIDE_COPY_ATTRIBUTE
53   // additional check
54   if (theConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) {
55     // If it is translation
56     AttributePoint2DPtr aStart = GeomDataAPI_Point2D::getPoint2D(aData,
57                                             SketchPlugin_MultiTranslation::START_POINT_ID());
58     AttributePoint2DPtr aEnd = GeomDataAPI_Point2D::getPoint2D(aData,
59                                             SketchPlugin_MultiTranslation::END_POINT_ID());
60
61     aReadyToDisplay = aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized();
62   }
63   else if (theConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
64     // if it is rotation
65     AttributePoint2DPtr aCenter = GeomDataAPI_Point2D::getPoint2D(aData, SketchPlugin_MultiRotation::CENTER_ID());
66     aReadyToDisplay = aCenter.get() && aCenter->isInitialized();
67   }
68 #endif
69   return aReadyToDisplay;
70 }
71
72 bool SketcherPrs_Transformation::updateIfReadyToDisplay(double theStep) const 
73 {
74   if (!IsReadyToDisplay(myConstraint, myPlane))
75     return false;
76
77   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
78   // Get transformated objects list
79   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
80
81   int aNbB = anAttrB->size();
82   if (aNbB == 0)
83   {
84 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
85   //if (!myPntArray.IsNull())
86     //  mySPoints.Clear();
87 #endif
88   }
89
90   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
91   myPntArray = new Graphic3d_ArrayOfPoints(aNbB);
92
93   int i;
94   ObjectPtr aObj;
95   gp_Pnt aP1;
96   // Compute points of symbols
97   for (i = 0; i < aNbB; i++) {
98     aObj = anAttrB->object(i);
99     if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
100       continue;
101     aP1 = aMgr->getPosition(aObj, this, theStep);
102     myPntArray->SetVertice(i + 1, aP1);
103   }  
104
105   return true;
106 }
107
108 void SketcherPrs_Transformation::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
109 {
110   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
111   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
112   if (anAttrB.get() == NULL)
113     return;
114
115   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
116
117   //Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
118   //aGroup->SetPrimitivesAspect(aLineAspect);
119
120   // drawListOfShapes uses myDrawer for attributes definition
121   Handle(Prs3d_LineAspect) aLnAspect = new Prs3d_LineAspect(theColor, Aspect_TOL_SOLID, 1);
122   myDrawer->SetLineAspect(aLnAspect);
123
124   drawListOfShapes(anAttrB, thePrs);
125   if (myConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) {
126     // If it is translation
127     AttributePoint2DPtr aStart = GeomDataAPI_Point2D::getPoint2D(aData,
128                                             SketchPlugin_MultiTranslation::START_POINT_ID());
129     AttributePoint2DPtr aEnd = GeomDataAPI_Point2D::getPoint2D(aData,
130                                             SketchPlugin_MultiTranslation::END_POINT_ID());
131
132     if (aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized()) {
133       // Add start point
134       std::shared_ptr<GeomAPI_Pnt> aPnt = myPlane->to3D(aStart->x(), aStart->y());
135       Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
136       StdPrs_Point::Add(thePrs, aPoint, myDrawer);
137
138       // Add end point
139       aPnt = myPlane->to3D(aEnd->x(), aEnd->y());
140       aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
141       StdPrs_Point::Add(thePrs, aPoint, myDrawer);
142     }
143   } else if (myConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
144     // if it is rotation
145     AttributePoint2DPtr aCenter = GeomDataAPI_Point2D::getPoint2D(aData, SketchPlugin_MultiRotation::CENTER_ID());
146     if (aCenter.get() && aCenter->isInitialized()) {
147       // Show center of rotation
148       std::shared_ptr<GeomAPI_Pnt> aPnt = myPlane->to3D(aCenter->x(), aCenter->y());
149       Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
150       StdPrs_Point::Add(thePrs, aPoint, myDrawer);
151     }
152   }
153 }
154