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