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_RTTIEXT(SketcherPrs_Middle, SketcherPrs_SymbolPrs);
19 static Handle(Image_AlienPixMap) MyPixMap;
21 SketcherPrs_Middle::SketcherPrs_Middle(ModelAPI_Feature* theConstraint,
22 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
23 : SketcherPrs_SymbolPrs(theConstraint, thePlane)
27 bool SketcherPrs_Middle::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
28 const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
30 bool aReadyToDisplay = false;
33 SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
35 SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B());
37 // one object is a feature Line, other object is a point result. We check shape of point result
38 aReadyToDisplay = aObj1.get() && aObj2.get() &&
39 (SketcherPrs_Tools::getShape(aObj1).get() != NULL ||
40 SketcherPrs_Tools::getShape(aObj2).get() != NULL);
42 return aReadyToDisplay;
45 bool SketcherPrs_Middle::updateIfReadyToDisplay(double theStep) const
47 if (!IsReadyToDisplay(myConstraint, myPlane))
49 ObjectPtr aPointObject;
51 // find a line result to set middle symbol near it
52 AttributePtr anAttribute =
53 SketcherPrs_Tools::getAttribute(myConstraint, SketchPlugin_Constraint::ENTITY_A());
54 if (!anAttribute.get()) {
56 SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
57 std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
58 if (aShape.get() && aShape->isEdge())
61 if (!aPointObject.get()) {
63 SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
64 std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
65 if (aShape.get() && aShape->isEdge())
69 if (!aPointObject.get())
72 // Set points of the presentation
73 SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
74 gp_Pnt aP1 = aMgr->getPosition(aPointObject, this, theStep);
75 myPntArray->SetVertice(1, aP1);
79 void SketcherPrs_Middle::drawLines(const Handle(Prs3d_Presentation)& thePrs,
80 Quantity_Color theColor) const
82 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
84 Handle(Graphic3d_AspectLine3d) aLineAspect =
85 new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
86 aGroup->SetPrimitivesAspect(aLineAspect);
90 SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
91 drawLine(thePrs, theColor, aObject);
93 aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
94 drawLine(thePrs, theColor, aObject);
97 void SketcherPrs_Middle::drawLine(const Handle(Prs3d_Presentation)& thePrs,
98 Quantity_Color theColor, const ObjectPtr& theObject) const
100 FeaturePtr aLineFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
101 if (aLineFeature.get()) {
102 std::list<ResultPtr> aResults = aLineFeature->results();
103 if (aResults.size() == 1) {
104 ResultPtr aResult = aResults.front();
105 std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aResult);
106 if (aLine.get() != NULL)
107 drawShape(aLine, thePrs);
111 std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(theObject);
112 if (aLine.get() != NULL)
113 drawShape(aLine, thePrs);