Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Coincident.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Coincident.cpp
4 // Created:     12 February 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Coincident.h"
8 #include "SketcherPrs_Tools.h"
9
10 #include <ModelAPI_AttributeRefAttr.h>
11 #include <GeomDataAPI_Point2D.h>
12 #include <GeomDataAPI_Dir.h>
13 #include <GeomDataAPI_Point.h>
14
15 #include <GeomAPI_XYZ.h>
16 #include <GeomAPI_Dir.h>
17 #include <GeomAPI_Pnt2d.h>
18
19 #include <SketchPlugin_Point.h>
20 #include <SketchPlugin_Circle.h>
21 #include <SketchPlugin_Constraint.h>
22
23 #include <AIS_Drawer.hxx>
24 #include <Graphic3d_AspectMarker3d.hxx>
25 #include <Graphic3d_ArrayOfPoints.hxx>
26 #include <Prs3d_PointAspect.hxx>
27 #include <Prs3d_Root.hxx>
28 #include <SelectMgr_EntityOwner.hxx>
29 #include <SelectMgr_Selection.hxx>
30 #include <Select3D_SensitivePoint.hxx>
31
32
33 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject);
34 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject);
35
36 SketcherPrs_Coincident::SketcherPrs_Coincident(SketchPlugin_Constraint* theConstraint, 
37                                                const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
38  : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
39 {
40   
41 }  
42
43
44
45 void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
46                                    const Handle(Prs3d_Presentation)& thePresentation, 
47                                    const Standard_Integer theMode)
48 {
49   std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint, 
50                                                                     SketchPlugin_Constraint::ENTITY_A());
51   if (aPnt.get() == NULL)
52     return;
53
54   std::shared_ptr<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y());
55   myPoint = aPoint->impl<gp_Pnt>();
56
57   static Handle(Graphic3d_AspectMarker3d) aPtA;
58   if (aPtA.IsNull()) {
59     aPtA = new Graphic3d_AspectMarker3d ();
60     aPtA->SetType(Aspect_TOM_RING1);
61     aPtA->SetScale(2.);
62     aPtA->SetColor(myOwnColor);
63   }
64   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
65   aGroup->SetPrimitivesAspect(aPtA);
66   Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
67   aPntArray->AddVertex (aPoint->x(), aPoint->y(), aPoint->z());
68   aGroup->AddPrimitiveArray (aPntArray);
69 }
70
71
72 void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
73                                             const Standard_Integer aMode)
74 {
75   Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this, 10);
76   Handle(Select3D_SensitivePoint) aSp = new Select3D_SensitivePoint(aOwn, myPoint);
77   aSelection->Add(aSp);
78 }
79
80 void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
81 {
82   SetColor(Quantity_Color(aCol));
83 }
84
85 void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol)
86 {
87   hasOwnColor=Standard_True;
88   myOwnColor=aCol;
89 }