1 // Copyright (C) 2014-2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SketcherPrs_Coincident.h"
21 #include "SketcherPrs_Tools.h"
23 #include <ModelAPI_AttributeRefAttr.h>
24 #include <ModelAPI_Events.h>
26 #include <GeomDataAPI_Point2D.h>
27 #include <GeomDataAPI_Dir.h>
28 #include <GeomDataAPI_Point.h>
30 #include <GeomAPI_XYZ.h>
31 #include <GeomAPI_Dir.h>
32 #include <GeomAPI_Pnt2d.h>
34 #include <SketchPlugin_Constraint.h>
35 #include <SketchPlugin_ConstraintCoincidence.h>
37 #include <AIS_InteractiveContext.hxx>
38 #include <Graphic3d_AspectMarker3d.hxx>
39 #include <Graphic3d_ArrayOfPoints.hxx>
40 #include <Prs3d_PointAspect.hxx>
41 #include <Prs3d_Root.hxx>
42 #include <SelectMgr_EntityOwner.hxx>
43 #include <SelectMgr_Selection.hxx>
44 #include <Select3D_SensitivePoint.hxx>
47 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject);
49 SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint,
50 SketchPlugin_Sketch* theSketch)
51 : AIS_InteractiveObject(), myConstraint(theConstraint), mySketch(theSketch),
52 myPoint(gp_Pnt(0.0, 0.0, 0.0))
54 SetColor(Quantity_NOC_BLACK);
57 bool SketcherPrs_Coincident::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
58 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
61 return readyToDisplay(theConstraint, thePlane, aPoint);
64 std::shared_ptr<GeomAPI_Pnt2d> getCoincidencePoint(ModelAPI_Feature* theConstraint)
66 std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theConstraint,
67 SketchPlugin_Constraint::ENTITY_A());
68 if (aPnt.get() == NULL)
69 aPnt = SketcherPrs_Tools::getPoint(theConstraint, SketchPlugin_Constraint::ENTITY_B());
75 bool SketcherPrs_Coincident::readyToDisplay(ModelAPI_Feature* theConstraint,
76 const std::shared_ptr<GeomAPI_Ax3>& thePlane,
79 bool aReadyToDisplay = false;
80 // Get point of the presentation
81 std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincidencePoint(theConstraint);
82 aReadyToDisplay = aPnt.get() != NULL;
83 if (aReadyToDisplay) {
84 std::shared_ptr<GeomAPI_Pnt> aPoint = thePlane->to3D(aPnt->x(), aPnt->y());
85 thePoint = aPoint->impl<gp_Pnt>();
87 return aReadyToDisplay;
91 bool hasEdge(ModelAPI_Feature* theConstraint)
94 SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
96 SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B());
97 ResultPtr aResA = std::dynamic_pointer_cast<ModelAPI_Result>(aObjA);
98 ResultPtr aResB = std::dynamic_pointer_cast<ModelAPI_Result>(aObjB);
100 GeomAPI_Shape::ShapeType aTypeA = aResA->shape()->shapeType();
101 if (aTypeA == GeomAPI_Shape::EDGE)
105 GeomAPI_Shape::ShapeType aTypeB = aResB->shape()->shapeType();
106 if (aTypeB == GeomAPI_Shape::EDGE)
113 void SketcherPrs_Coincident::Compute(
114 const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/,
115 const Handle(Prs3d_Presentation)& thePresentation,
116 const Standard_Integer /*theMode*/)
119 bool aReadyToDisplay = readyToDisplay(myConstraint, mySketch->coordinatePlane(), aPoint);
123 bool aIsEdge = hasEdge(myConstraint);
125 std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincidencePoint(myConstraint);
126 std::shared_ptr<GeomAPI_Pnt2d> aP;
128 int aNumberOfSubs = mySketch->numberOfSubs();
129 for (int i = 0; i < aNumberOfSubs; i++) {
130 aSub = mySketch->subFeature(i);
131 if (aSub->getKind() == SketchPlugin_ConstraintCoincidence::ID() &&
132 aSub.get() != myConstraint) {
133 aP = getCoincidencePoint(aSub.get());
134 if (aP && aP->isEqual(aPnt)) {
135 aIsEdge = hasEdge(aSub.get());
142 Quantity_Color aMainColor;
144 Quantity_Color aExternalColor = aIsEdge ? aMainColor : Quantity_NOC_YELLOW;
145 Quantity_Color aInternalColor = aIsEdge ? Quantity_NOC_YELLOW : aMainColor;
147 int aRatio = SketcherPrs_Tools::pixelRatio();
149 // Create the presentation as a combination of standard point markers
150 // The external yellow contour
151 Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d();
152 aPtA->SetType(Aspect_TOM_RING3);
153 aPtA->SetScale(2. * aRatio);
154 aPtA->SetColor(aExternalColor);
156 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
157 aGroup->SetPrimitivesAspect(aPtA);
158 Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
159 aPntArray->AddVertex (myPoint.X(), myPoint.Y(), myPoint.Z());
160 aGroup->AddPrimitiveArray (aPntArray);
162 // Make a black mid ring
163 aPtA = new Graphic3d_AspectMarker3d();
164 aPtA->SetType(aIsEdge ? Aspect_TOM_STAR : Aspect_TOM_RING1);
165 aPtA->SetScale(1. * aRatio);
166 aPtA->SetColor(aInternalColor);
167 aGroup->SetPrimitivesAspect(aPtA);
168 aGroup->AddPrimitiveArray (aPntArray);
170 // Make an internal ring
171 aPtA = new Graphic3d_AspectMarker3d();
172 aPtA->SetType(Aspect_TOM_POINT);
173 aPtA->SetScale(5. * aRatio);
174 aPtA->SetColor(aInternalColor);
175 aGroup->SetPrimitivesAspect(aPtA);
176 aGroup->AddPrimitiveArray (aPntArray);
178 if (!aReadyToDisplay)
179 SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
180 "An empty AIS presentation: SketcherPrs_Coincident");
184 void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& /*theSelection*/,
185 const Standard_Integer /*theMode*/)
187 // There is no selection of coincident - a point is selected instead of coincidence