1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SketcherPrs_Transformation.h"
21 #include "SketcherPrs_Tools.h"
22 #include "SketcherPrs_PositionMgr.h"
24 #include <SketchPlugin_Constraint.h>
25 #include <SketchPlugin_MultiTranslation.h>
26 #include <SketchPlugin_MultiRotation.h>
27 #include <ModelAPI_AttributeRefList.h>
28 #include <GeomDataAPI_Point2D.h>
30 #include <Graphic3d_AspectLine3d.hxx>
31 #include <Prs3d_Root.hxx>
32 #include <Prs3d_LineAspect.hxx>
33 #include <Geom_CartesianPoint.hxx>
35 #include <StdPrs_Point.hxx>
39 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Transformation, SketcherPrs_SymbolPrs);
41 static Handle(Image_AlienPixMap) MyPixMap;
43 SketcherPrs_Transformation::SketcherPrs_Transformation(ModelAPI_Feature* theConstraint,
44 SketchPlugin_Sketch* theSketcher,
46 : SketcherPrs_SymbolPrs(theConstraint, theSketcher), myIsTranslation(isTranslation)
50 bool SketcherPrs_Transformation::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
51 const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
53 bool aReadyToDisplay = false;
55 std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
56 // Get transformated objects list
57 std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
58 aData->reflist(SketchPlugin_Constraint::ENTITY_B());
59 if (anAttrB.get() == NULL)
60 return aReadyToDisplay;
62 int aNbB = anAttrB->size();
63 aReadyToDisplay = aNbB > 0;
65 #ifdef DEBUG_HIDE_COPY_ATTRIBUTE
67 if (theConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) {
68 // If it is translation
69 AttributePoint2DPtr aStart = GeomDataAPI_Point2D::getPoint2D(aData,
70 SketchPlugin_MultiTranslation::START_POINT_ID());
71 AttributePoint2DPtr aEnd = GeomDataAPI_Point2D::getPoint2D(aData,
72 SketchPlugin_MultiTranslation::END_POINT_ID());
75 aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized();
77 else if (theConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
79 AttributePoint2DPtr aCenter =
80 GeomDataAPI_Point2D::getPoint2D(aData, SketchPlugin_MultiRotation::CENTER_ID());
81 aReadyToDisplay = aCenter.get() && aCenter->isInitialized();
84 return aReadyToDisplay;
87 bool SketcherPrs_Transformation::updateIfReadyToDisplay(double theStep, bool withColor) const
89 if (!IsReadyToDisplay(myConstraint, plane()))
92 std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
93 // Get transformated objects list
94 std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
95 aData->reflist(SketchPlugin_Constraint::ENTITY_B());
97 int aNbB = anAttrB->size();
100 #ifdef DEBUG_SENSITIVE_TO_BE_CORRECTED
101 //if (!myPntArray.IsNull())
102 // mySPoints.Clear();
106 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
107 myPntArray = new Graphic3d_ArrayOfPoints(aNbB, withColor);
112 // Compute points of symbols
113 for (i = 0; i < aNbB; i++) {
114 aObj = anAttrB->object(i);
115 if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
117 aP1 = aMgr->getPosition(aObj, this, theStep);
118 myPntArray->SetVertice(i + 1, aP1);
124 void SketcherPrs_Transformation::drawLines(const Handle(Prs3d_Presentation)& thePrs,
125 Quantity_Color theColor) const
127 std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
128 std::shared_ptr<ModelAPI_AttributeRefList> anAttrB =
129 aData->reflist(SketchPlugin_Constraint::ENTITY_B());
130 if (anAttrB.get() == NULL)
133 // drawListOfShapes uses myDrawer for attributes definition
134 //Handle(Prs3d_LineAspect) aLnAspect = new Prs3d_LineAspect(theColor, Aspect_TOL_SOLID, 1);
135 //myDrawer->SetLineAspect(aLnAspect);
137 drawListOfShapes(anAttrB, thePrs, theColor);
138 if (myConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) {
139 // If it is translation
140 AttributePoint2DPtr aStart = GeomDataAPI_Point2D::getPoint2D(aData,
141 SketchPlugin_MultiTranslation::START_POINT_ID());
142 AttributePoint2DPtr aEnd = GeomDataAPI_Point2D::getPoint2D(aData,
143 SketchPlugin_MultiTranslation::END_POINT_ID());
145 if (aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized()) {
147 std::shared_ptr<GeomAPI_Pnt> aPnt = plane()->to3D(aStart->x(), aStart->y());
148 Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
149 StdPrs_Point::Add(thePrs, aPoint, myDrawer);
152 aPnt = plane()->to3D(aEnd->x(), aEnd->y());
153 aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
154 StdPrs_Point::Add(thePrs, aPoint, myDrawer);
156 } else if (myConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
158 AttributePoint2DPtr aCenter =
159 GeomDataAPI_Point2D::getPoint2D(aData, SketchPlugin_MultiRotation::CENTER_ID());
160 if (aCenter.get() && aCenter->isInitialized()) {
161 // Show center of rotation
162 std::shared_ptr<GeomAPI_Pnt> aPnt = plane()->to3D(aCenter->x(), aCenter->y());
163 Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
164 StdPrs_Point::Add(thePrs, aPoint, myDrawer);