1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_Transformation.cpp
4 // Created: 16 February 2015
5 // Author: Vitaly SMETANNIKOV
7 #include "SketcherPrs_Transformation.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
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>
17 #include <Graphic3d_AspectLine3d.hxx>
18 #include <Prs3d_Root.hxx>
19 #include <Prs3d_LineAspect.hxx>
20 #include <Geom_CartesianPoint.hxx>
22 #include <StdPrs_Point.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
28 static Handle(Image_AlienPixMap) MyPixMap;
30 SketcherPrs_Transformation::SketcherPrs_Transformation(ModelAPI_Feature* theConstraint,
31 const std::shared_ptr<GeomAPI_Ax3>& thePlane,
33 : SketcherPrs_SymbolPrs(theConstraint, thePlane), myIsTranslation(isTranslation)
37 bool SketcherPrs_Transformation::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
38 const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
40 bool aReadyToDisplay = false;
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;
49 int aNbB = anAttrB->size();
50 aReadyToDisplay = aNbB > 0;
52 #ifdef DEBUG_HIDE_COPY_ATTRIBUTE
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());
62 aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized();
64 else if (theConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
66 AttributePoint2DPtr aCenter =
67 GeomDataAPI_Point2D::getPoint2D(aData, SketchPlugin_MultiRotation::CENTER_ID());
68 aReadyToDisplay = aCenter.get() && aCenter->isInitialized();
71 return aReadyToDisplay;
74 bool SketcherPrs_Transformation::updateIfReadyToDisplay(double theStep, bool withColor) const
76 if (!IsReadyToDisplay(myConstraint, myPlane))
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());
84 int aNbB = anAttrB->size();
87 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
88 //if (!myPntArray.IsNull())
93 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
94 myPntArray = new Graphic3d_ArrayOfPoints(aNbB, withColor);
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)
104 aP1 = aMgr->getPosition(aObj, this, theStep);
105 myPntArray->SetVertice(i + 1, aP1);
111 void SketcherPrs_Transformation::drawLines(const Handle(Prs3d_Presentation)& thePrs,
112 Quantity_Color theColor) const
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)
120 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
122 // drawListOfShapes uses myDrawer for attributes definition
123 Handle(Prs3d_LineAspect) aLnAspect = new Prs3d_LineAspect(theColor, Aspect_TOL_SOLID, 1);
124 myDrawer->SetLineAspect(aLnAspect);
126 drawListOfShapes(anAttrB, thePrs);
127 if (myConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) {
128 // If it is translation
129 AttributePoint2DPtr aStart = GeomDataAPI_Point2D::getPoint2D(aData,
130 SketchPlugin_MultiTranslation::START_POINT_ID());
131 AttributePoint2DPtr aEnd = GeomDataAPI_Point2D::getPoint2D(aData,
132 SketchPlugin_MultiTranslation::END_POINT_ID());
134 if (aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized()) {
136 std::shared_ptr<GeomAPI_Pnt> aPnt = myPlane->to3D(aStart->x(), aStart->y());
137 Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
138 StdPrs_Point::Add(thePrs, aPoint, myDrawer);
141 aPnt = myPlane->to3D(aEnd->x(), aEnd->y());
142 aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
143 StdPrs_Point::Add(thePrs, aPoint, myDrawer);
145 } else if (myConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
147 AttributePoint2DPtr aCenter =
148 GeomDataAPI_Point2D::getPoint2D(aData, SketchPlugin_MultiRotation::CENTER_ID());
149 if (aCenter.get() && aCenter->isInitialized()) {
150 // Show center of rotation
151 std::shared_ptr<GeomAPI_Pnt> aPnt = myPlane->to3D(aCenter->x(), aCenter->y());
152 Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
153 StdPrs_Point::Add(thePrs, aPoint, myDrawer);