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_HANDLE(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
27 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
29 static Handle(Image_AlienPixMap) MyPixMap;
31 SketcherPrs_Transformation::SketcherPrs_Transformation(ModelAPI_Feature* theConstraint,
32 const std::shared_ptr<GeomAPI_Ax3>& thePlane,
34 : SketcherPrs_SymbolPrs(theConstraint, thePlane), myIsTranslation(isTranslation)
38 bool SketcherPrs_Transformation::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
39 const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
41 bool aReadyToDisplay = false;
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;
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());
61 aReadyToDisplay = aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized();
63 else if (theConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
65 AttributePoint2DPtr aCenter = GeomDataAPI_Point2D::getPoint2D(aData, SketchPlugin_MultiRotation::CENTER_ID());
66 aReadyToDisplay = aCenter.get() && aCenter->isInitialized();
69 return aReadyToDisplay;
72 bool SketcherPrs_Transformation::updateIfReadyToDisplay(double theStep) const
74 if (!IsReadyToDisplay(myConstraint, myPlane))
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());
81 int aNbB = anAttrB->size();
84 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
85 //if (!myPntArray.IsNull())
90 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
91 myPntArray = new Graphic3d_ArrayOfPoints(aNbB);
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)
101 aP1 = aMgr->getPosition(aObj, this, theStep);
102 myPntArray->SetVertice(i + 1, aP1);
108 void SketcherPrs_Transformation::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
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)
115 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
117 //Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
118 //aGroup->SetPrimitivesAspect(aLineAspect);
120 // drawListOfShapes uses myDrawer for attributes definition
121 Handle(Prs3d_LineAspect) aLnAspect = new Prs3d_LineAspect(theColor, Aspect_TOL_SOLID, 1);
122 myDrawer->SetLineAspect(aLnAspect);
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());
132 if (aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized()) {
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);
139 aPnt = myPlane->to3D(aEnd->x(), aEnd->y());
140 aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
141 StdPrs_Point::Add(thePrs, aPoint, myDrawer);
143 } else if (myConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
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);