1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_Middle.cpp
4 // Created: 29 February 2016
5 // Author: Natalia ERMOLAEVA
7 #include "SketcherPrs_Middle.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
11 #include <SketchPlugin_Constraint.h>
13 #include <Graphic3d_AspectLine3d.hxx>
14 #include <Prs3d_Root.hxx>
17 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Middle, SketcherPrs_SymbolPrs);
18 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Middle, SketcherPrs_SymbolPrs);
20 static Handle(Image_AlienPixMap) MyPixMap;
22 SketcherPrs_Middle::SketcherPrs_Middle(ModelAPI_Feature* theConstraint,
23 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
24 : SketcherPrs_SymbolPrs(theConstraint, thePlane)
28 bool SketcherPrs_Middle::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
29 const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
31 bool aReadyToDisplay = false;
34 SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
36 SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B());
38 // one object is a feature Line, other object is a point result. We check shape of point result
39 aReadyToDisplay = aObj1.get() && aObj2.get() &&
40 (SketcherPrs_Tools::getShape(aObj1).get() != NULL ||
41 SketcherPrs_Tools::getShape(aObj2).get() != NULL);
43 return aReadyToDisplay;
46 bool SketcherPrs_Middle::updateIfReadyToDisplay(double theStep) const
48 if (!IsReadyToDisplay(myConstraint, myPlane))
50 ObjectPtr aPointObject;
52 // find a line result to set middle symbol near it
53 AttributePtr anAttribute =
54 SketcherPrs_Tools::getAttribute(myConstraint, SketchPlugin_Constraint::ENTITY_A());
55 if (!anAttribute.get()) {
57 SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
58 std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
59 if (aShape.get() && aShape->isEdge())
62 if (!aPointObject.get()) {
64 SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
65 std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
66 if (aShape.get() && aShape->isEdge())
70 if (!aPointObject.get())
73 // Set points of the presentation
74 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
75 gp_Pnt aP1 = aMgr->getPosition(aPointObject, this, theStep);
76 myPntArray->SetVertice(1, aP1);
80 void SketcherPrs_Middle::drawLines(const Handle(Prs3d_Presentation)& thePrs,
81 Quantity_Color theColor) const
83 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
85 Handle(Graphic3d_AspectLine3d) aLineAspect =
86 new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
87 aGroup->SetPrimitivesAspect(aLineAspect);
91 SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
92 drawLine(thePrs, theColor, aObject);
94 aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
95 drawLine(thePrs, theColor, aObject);
98 void SketcherPrs_Middle::drawLine(const Handle(Prs3d_Presentation)& thePrs,
99 Quantity_Color theColor, const ObjectPtr& theObject) const
101 FeaturePtr aLineFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
102 if (aLineFeature.get()) {
103 std::list<ResultPtr> aResults = aLineFeature->results();
104 if (aResults.size() == 1) {
105 ResultPtr aResult = aResults.front();
106 std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aResult);
107 if (aLine.get() != NULL)
108 drawShape(aLine, thePrs);
112 std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(theObject);
113 if (aLine.get() != NULL)
114 drawShape(aLine, thePrs);