Salome HOME
Fix colors of highlighting of symbol constraints
[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_RTTIEXT(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
27
28 static Handle(Image_AlienPixMap) MyPixMap;
29
30 SketcherPrs_Transformation::SketcherPrs_Transformation(ModelAPI_Feature* theConstraint,
31                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane,
32                                            bool isTranslation)
33  : SketcherPrs_SymbolPrs(theConstraint, thePlane), myIsTranslation(isTranslation)
34 {
35 }
36
37 bool SketcherPrs_Transformation::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
38                                                   const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
39 {
40   bool aReadyToDisplay = false;
41
42   std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
43   // Get transformated objects list
44   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
45     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 =
62       aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized();
63   }
64   else if (theConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
65     // if it is rotation
66     AttributePoint2DPtr aCenter =
67       GeomDataAPI_Point2D::getPoint2D(aData, SketchPlugin_MultiRotation::CENTER_ID());
68     aReadyToDisplay = aCenter.get() && aCenter->isInitialized();
69   }
70 #endif
71   return aReadyToDisplay;
72 }
73
74 bool SketcherPrs_Transformation::updateIfReadyToDisplay(double theStep, bool withColor) const
75 {
76   if (!IsReadyToDisplay(myConstraint, myPlane))
77     return false;
78
79   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
80   // Get transformated objects list
81   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
82     aData->reflist(SketchPlugin_Constraint::ENTITY_B());
83
84   int aNbB = anAttrB->size();
85   if (aNbB == 0)
86   {
87 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
88   //if (!myPntArray.IsNull())
89     //  mySPoints.Clear();
90 #endif
91   }
92
93   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
94   myPntArray = new Graphic3d_ArrayOfPoints(aNbB, withColor);
95
96   int i;
97   ObjectPtr aObj;
98   gp_Pnt aP1;
99   // Compute points of symbols
100   for (i = 0; i < aNbB; i++) {
101     aObj = anAttrB->object(i);
102     if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
103       continue;
104     aP1 = aMgr->getPosition(aObj, this, theStep);
105     myPntArray->SetVertice(i + 1, aP1);
106   }
107
108   return true;
109 }
110
111 void SketcherPrs_Transformation::drawLines(const Handle(Prs3d_Presentation)& thePrs,
112                                            Quantity_Color theColor) const
113 {
114   std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
115   std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
116     aData->reflist(SketchPlugin_Constraint::ENTITY_B());
117   if (anAttrB.get() == NULL)
118     return;
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, theColor);
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 =
146       GeomDataAPI_Point2D::getPoint2D(aData, SketchPlugin_MultiRotation::CENTER_ID());
147     if (aCenter.get() && aCenter->isInitialized()) {
148       // Show center of rotation
149       std::shared_ptr<GeomAPI_Pnt> aPnt = myPlane->to3D(aCenter->x(), aCenter->y());
150       Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
151       StdPrs_Point::Add(thePrs, aPoint, myDrawer);
152     }
153   }
154 }
155