Salome HOME
Fix for a crash: Create sketch, circle, Radius constraint with 0 value.
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Tangent.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Tangent.cpp
4 // Created:     16 February 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Tangent.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
10
11 #include <GeomAPI_Curve.h>
12
13 #include <SketchPlugin_Constraint.h>
14
15 #include <GeomAdaptor_Curve.hxx>
16 #include <Prs3d_Root.hxx>
17 #include <Graphic3d_AspectLine3d.hxx>
18 #include <StdPrs_DeflectionCurve.hxx>
19
20
21 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Tangent, SketcherPrs_SymbolPrs);
22 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Tangent, SketcherPrs_SymbolPrs);
23
24 static Handle(Image_AlienPixMap) MyPixMap;
25
26 SketcherPrs_Tangent::SketcherPrs_Tangent(ModelAPI_Feature* theConstraint, 
27                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
28  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
29 {
30   myPntArray = new Graphic3d_ArrayOfPoints(2);
31   myPntArray->AddVertex(0., 0., 0.);
32   myPntArray->AddVertex(0., 0., 0.);
33 }  
34
35 bool SketcherPrs_Tangent::updatePoints(double theStep) const
36 {
37   ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
38   ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
39   if (SketcherPrs_Tools::getShape(aObj1).get() == NULL)
40     return false;
41   if (SketcherPrs_Tools::getShape(aObj2).get() == NULL)
42     return false;
43
44   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
45   gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep);
46   gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
47   myPntArray->SetVertice(1, aP1);
48   myPntArray->SetVertice(2, aP2);
49   return true;
50 }
51
52 void SketcherPrs_Tangent::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
53 {
54   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
55
56   Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
57   aGroup->SetPrimitivesAspect(aLineAspect);
58
59   ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
60   ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
61
62   std::shared_ptr<GeomAPI_Shape> aShape1 = SketcherPrs_Tools::getShape(aObj1);
63   std::shared_ptr<GeomAPI_Shape> aShape2 = SketcherPrs_Tools::getShape(aObj2);
64
65   if ((aShape1.get() == NULL) || (aShape2.get() == NULL))
66     return;
67   drawShape(aShape1, thePrs);
68   drawShape(aShape2, thePrs);
69 }
70