Salome HOME
Fix colors of highlighting of symbol constraints
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Perpendicular.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Perpendicular.cpp
4 // Created:     12 March 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Perpendicular.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
18 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Perpendicular, SketcherPrs_SymbolPrs);
19
20 static Handle(Image_AlienPixMap) MyPixMap;
21
22 SketcherPrs_Perpendicular::SketcherPrs_Perpendicular(ModelAPI_Feature* theConstraint,
23                                                      const std::shared_ptr<GeomAPI_Ax3>& thePlane)
24  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
25 {
26 }
27
28 bool SketcherPrs_Perpendicular::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   aReadyToDisplay = SketcherPrs_Tools::getShape(aObj1).get() != NULL &&
39                     SketcherPrs_Tools::getShape(aObj2).get() != NULL;
40   return aReadyToDisplay;
41 }
42
43 bool SketcherPrs_Perpendicular::updateIfReadyToDisplay(double theStep, bool withColor) const
44 {
45   if (!IsReadyToDisplay(myConstraint, myPlane))
46     return false;
47
48   ObjectPtr aObj1 =
49     SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
50   ObjectPtr aObj2 =
51     SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
52
53   // Compute position of symbols
54   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
55   gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep);
56   gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
57   myPntArray = new Graphic3d_ArrayOfPoints(2, withColor);
58   myPntArray->AddVertex(aP1);
59   myPntArray->AddVertex(aP2);
60   return true;
61 }
62
63
64 void SketcherPrs_Perpendicular::drawLines(const Handle(Prs3d_Presentation)& thePrs,
65                                           Quantity_Color theColor) const
66 {
67   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePrs);
68
69   Handle(Graphic3d_AspectLine3d) aLineAspect =
70     new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
71   aGroup->SetPrimitivesAspect(aLineAspect);
72
73   // Draw constrained lines
74   addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
75   addLine(aGroup, SketchPlugin_Constraint::ENTITY_B());
76 }
77