1 // Copyright (C) 2019-2022 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 "SketchAPI_MacroMiddlePoint.h"
22 #include <ModelHighAPI_RefAttr.h>
24 #include <SketchPlugin_ConstraintMiddle.h>
28 SketchAPI_MacroMiddlePoint::SketchAPI_MacroMiddlePoint(
29 const std::shared_ptr<ModelAPI_Feature> & theFeature)
30 : SketchAPI_Point(theFeature)
32 ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(theFeature);
37 SketchAPI_MacroMiddlePoint::SketchAPI_MacroMiddlePoint(const std::shared_ptr<ModelAPI_Feature>& theFeature,
38 const ModelHighAPI_RefAttr& theLine, const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
39 : SketchAPI_Point(theFeature, thePoint)
41 createConstraint(theLine);
44 void SketchAPI_MacroMiddlePoint::createConstraint(const ModelHighAPI_RefAttr& theLine)
47 CompositeFeaturePtr aSketch;
48 const std::set<AttributePtr>& aRefs = feature()->data()->refsToMe();
49 for (std::set<AttributePtr>::const_iterator anIt = aRefs.begin(); anIt != aRefs.end(); ++anIt)
50 if ((*anIt)->id() == SketchPlugin_Sketch::FEATURES_ID())
52 aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
58 // Create middle constraint for line and poiunt
59 std::shared_ptr<ModelAPI_Feature> aConstrFeature =
60 aSketch->addFeature(SketchPlugin_ConstraintMiddle::ID());
61 aConstrFeature->string(SketchPlugin_ConstraintMiddle::MIDDLE_TYPE())->setValue(SketchPlugin_ConstraintMiddle::MIDDLE_TYPE_BY_LINE());
62 aConstrFeature->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject(theLine.object());
63 aConstrFeature->refattr(SketchPlugin_Constraint::ENTITY_B())->setAttr(coordinates());
64 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aConstrFeature->attribute(SketchPlugin_ConstraintMiddle::POINT_REF_ID()))->setValue(coordinates()->x(), coordinates()->y());
66 aConstrFeature->execute();
68 feature()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->setValue(true);
69 feature()->reference(SketchPlugin_SketchEntity::PARENT_ID())->setValue(aConstrFeature);