]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp
Salome HOME
[bos #37570] [CEA] SHAPER hdf tests are failing. Fix Sphere feature attributes order.
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintCoincidence.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "SketchPlugin_ConstraintCoincidence.h"
21
22 #include <SketchPlugin_Point.h>
23 #include <SketchPlugin_Line.h>
24 #include <SketchPlugin_Arc.h>
25 #include <SketchPlugin_Circle.h>
26
27 #include <ModelAPI_Events.h>
28 #include <ModelGeomAlgo_Point2D.h>
29 #include <GeomDataAPI_Point2D.h>
30
31 #include <SketcherPrs_Factory.h>
32
33 #include <Events_Loop.h>
34
35 SketchPlugin_ConstraintCoincidence::SketchPlugin_ConstraintCoincidence()
36 {
37 }
38
39 void SketchPlugin_ConstraintCoincidence::initAttributes()
40 {
41   data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
42   data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
43 }
44
45 void SketchPlugin_ConstraintCoincidence::execute()
46 {
47 }
48
49 AISObjectPtr SketchPlugin_ConstraintCoincidence::getAISObject(AISObjectPtr thePrevious)
50 {
51   if (!sketch())
52     return thePrevious;
53
54   AISObjectPtr anAIS = SketcherPrs_Factory::coincidentConstraint(this, sketch(), thePrevious);
55   return anAIS;
56 }
57
58 AttributePoint2DPtr SketchPlugin_ConstraintCoincidence::getPoint(const FeaturePtr& theFeature)
59 {
60   AttributePoint2DPtr aPoint = ModelGeomAlgo_Point2D::getPointOfRefAttr(theFeature.get(),
61                                                          SketchPlugin_Constraint::ENTITY_A(),
62                                  SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
63   if (!aPoint.get())
64     aPoint = ModelGeomAlgo_Point2D::getPointOfRefAttr(theFeature.get(),
65                                                       SketchPlugin_Constraint::ENTITY_B(),
66                                  SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
67   return aPoint;
68 }
69
70 void SketchPlugin_ConstraintCoincidence::createCoincidenceFeature(SketchPlugin_Sketch* theSketch,
71                                            const std::shared_ptr<GeomDataAPI_Point2D>& thePoint1,
72                                            const std::shared_ptr<GeomDataAPI_Point2D>& thePoint2)
73 {
74   FeaturePtr aFeature;
75   if (theSketch) {
76     aFeature = theSketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
77   } else {
78     std::shared_ptr<ModelAPI_Document> aDoc = theSketch->document();
79     aFeature = aDoc->addFeature(SketchPlugin_ConstraintCoincidence::ID());
80   }
81
82   std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
83
84   std::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 = std::dynamic_pointer_cast<
85       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
86   aRef1->setAttr(thePoint1);
87
88   std::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 = std::dynamic_pointer_cast<
89       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
90   aRef2->setAttr(thePoint2);
91
92   // we need to flush created signal in order to coincidence is processed by solver
93   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
94 }