Salome HOME
34c02875139054996100edcf9aaf381b7ea7791f
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Rigid.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Rigid.cpp
4 // Created:     16 February 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Rigid.h"
8 #include "SketcherPrs_Tools.h"
9 #include "SketcherPrs_PositionMgr.h"
10
11 #include <GeomAPI_Pnt.h>
12 #include <GeomAPI_Edge.h>
13 #include <GeomAPI_Curve.h>
14 #include <GeomAPI_Vertex.h>
15
16 #include <SketchPlugin_Constraint.h>
17
18 #include <AIS_Drawer.hxx>
19 #include <gp_Pnt2d.hxx>
20
21 #include <Prs3d_PointAspect.hxx>
22 #include <Prs3d_Root.hxx>
23 #include <Prs3d_LineAspect.hxx>
24
25 #include <Graphic3d_MarkerImage.hxx>
26 #include <Graphic3d_AspectMarker3d.hxx>
27 #include <Graphic3d_AspectLine3d.hxx>
28 #include <Graphic3d_ArrayOfSegments.hxx>
29
30 #include <Select3D_SensitivePoint.hxx>
31 #include <Select3D_SensitiveSegment.hxx>
32
33 #include <SelectMgr_SequenceOfOwner.hxx>
34 #include <SelectMgr_Selection.hxx>
35 #include <SelectMgr_EntityOwner.hxx>
36
37 #include <GeomAdaptor_Curve.hxx>
38 #include <BRep_Tool.hxx>
39 #include <StdPrs_DeflectionCurve.hxx>
40 #include <StdPrs_Point.hxx>
41 #include <Geom_CartesianPoint.hxx>
42
43
44
45 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Rigid, SketcherPrs_SymbolPrs);
46 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Rigid, SketcherPrs_SymbolPrs);
47
48 static Handle(Image_AlienPixMap) MyPixMap;
49
50 SketcherPrs_Rigid::SketcherPrs_Rigid(SketchPlugin_Constraint* theConstraint, 
51                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
52  : SketcherPrs_SymbolPrs(theConstraint, thePlane)
53 {
54   myPntArray = new Graphic3d_ArrayOfPoints(1);
55   myPntArray->AddVertex(0., 0., 0.);
56 }  
57
58 void SketcherPrs_Rigid::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
59                                    const Handle(Prs3d_Presentation)& thePresentation, 
60                                    const Standard_Integer theMode)
61 {
62   prepareAspect();
63
64   ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
65   std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
66   if (aLine1.get() == NULL)
67     return;
68
69   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
70   gp_Pnt aP1 = aMgr->getPosition(aObj1, this);
71
72   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
73   aGroup->SetPrimitivesAspect(myAspect);
74   myPntArray->SetVertice(1, aP1);
75   aGroup->AddPrimitiveArray(myPntArray);
76 }
77
78 void SketcherPrs_Rigid::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
79 {
80   ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
81   std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
82   if (aShape.get() == NULL)
83     return;
84
85   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
86   if (aShape->isEdge()) {
87     Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
88     aGroup->SetPrimitivesAspect(aLineAspect);
89     std::shared_ptr<GeomAPI_Curve> aCurve = std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(aShape));
90     if (aCurve->isLine()) {
91       addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
92     } else {
93       GeomAdaptor_Curve aAdaptor(aCurve->impl<Handle(Geom_Curve)>(), aCurve->startParam(), aCurve->endParam());
94       StdPrs_DeflectionCurve::Add(thePrs,aAdaptor,myDrawer);
95     }
96   } else {
97     // This is a point
98     Handle(Prs3d_PointAspect) aPntAspect = new Prs3d_PointAspect(Aspect_TOM_PLUS, theColor, 1);
99     myDrawer->SetPointAspect(aPntAspect);
100
101     std::shared_ptr<GeomAPI_Vertex> aVertex = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aShape));
102     std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
103     Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
104     StdPrs_Point::Add(thePrs, aPoint, myDrawer);
105   }
106 }
107