]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_Middle.cpp
Salome HOME
Remove extra files
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Middle.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Middle.cpp
4 // Created:     29 February 2016
5 // Author:      Natalia ERMOLAEVA
6
7 #include "SketcherPrs_Middle.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
10
11 #include <SketchPlugin_Constraint.h>
12
13 #include <Graphic3d_AspectLine3d.hxx>
14 #include <Prs3d_Root.hxx>
15
16
17 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Middle, SketcherPrs_SymbolPrs);
18 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Middle, SketcherPrs_SymbolPrs);
19
20 static Handle(Image_AlienPixMap) MyPixMap;
21
22 SketcherPrs_Middle::SketcherPrs_Middle(ModelAPI_Feature* theConstraint, 
23                                      const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
24  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
25 {
26 }
27
28 bool SketcherPrs_Middle::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
29                                          const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
30 {
31   bool aReadyToDisplay = false;
32
33   ObjectPtr aObj1 = 
34     SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
35   ObjectPtr aObj2 = 
36     SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B());
37
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);
42
43   return aReadyToDisplay;
44 }
45
46 bool SketcherPrs_Middle::updateIfReadyToDisplay(double theStep) const
47 {
48   if (!IsReadyToDisplay(myConstraint, myPlane))
49     return false;
50   ObjectPtr aPointObject;
51
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()) {
56     ObjectPtr aObj = 
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())
60       aPointObject = aObj;
61   }
62   if (!aPointObject.get()) {
63     ObjectPtr aObj = 
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())
67       aPointObject = aObj;
68   }
69
70   if (!aPointObject.get())
71     return false;
72
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);
77   return true;
78 }
79
80 void SketcherPrs_Middle::drawLines(const Handle(Prs3d_Presentation)& thePrs, 
81                                    Quantity_Color theColor) const
82 {
83   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
84
85   Handle(Graphic3d_AspectLine3d) aLineAspect = 
86     new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
87   aGroup->SetPrimitivesAspect(aLineAspect);
88
89   // Draw objects
90   ObjectPtr aObject = 
91     SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
92   drawLine(thePrs, theColor, aObject);
93
94   aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
95   drawLine(thePrs, theColor, aObject);
96 }
97
98 void SketcherPrs_Middle::drawLine(const Handle(Prs3d_Presentation)& thePrs,
99                                   Quantity_Color theColor, const ObjectPtr& theObject) const
100 {
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);
109     }
110   }
111   else {
112     std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(theObject);
113     if (aLine.get() != NULL)
114       drawShape(aLine, thePrs);
115   }
116 }
117