-// Copyright (C) 2019-2020 CEA/DEN, EDF R&D
+// Copyright (C) 2019-2023 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include <SketchPlugin_Tools.h>
#include <SketchPlugin_Sketch.h>
+#include <Locale_Convert.h>
+
#include <ModelAPI_AttributeDoubleArray.h>
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeRefAttrList.h>
#include <ModelAPI_Events.h>
-#include <ModelAPI_EventReentrantMessage.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
+#include <ModelAPI_Tools.h>
#include <GeomDataAPI_Point2DArray.h>
if (boolean(CONTROL_POLYGON_ID())->value()) {
std::list<FeaturePtr> aControlPoles;
- createControlPolygon(aBSpline, aControlPoles);
+ createControlPolygon(aBSpline, myIsPeriodic, aControlPoles);
constraintsForPoles(aControlPoles);
-
- // message to init reentrant operation
- static Events_ID anId = ModelAPI_EventReentrantMessage::eventId();
- ReentrantMessagePtr aMessage(new ModelAPI_EventReentrantMessage(anId, this));
- // set here the last pole to make coincidence with the start point of the next B-spline curve
- aMessage->setCreatedFeature(aControlPoles.back());
- Events_Loop::loop()->send(aMessage);
- }
-}
-
-// LCOV_EXCL_START
-std::string SketchPlugin_MacroBSpline::processEvent(
- const std::shared_ptr<Events_Message>& theMessage)
-{
- ReentrantMessagePtr aReentrantMessage =
- std::dynamic_pointer_cast<ModelAPI_EventReentrantMessage>(theMessage);
- if (aReentrantMessage) {
- FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
- ObjectPtr anObject = aReentrantMessage->selectedObject();
- AttributePtr anAttribute = aReentrantMessage->selectedAttribute();
- std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = aReentrantMessage->clickedPoint();
-
- if (aClickedPoint) {
- // fill points list (it consists of 2 points to make editable the second one)
- AttributePoint2DArrayPtr aPointArrayAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(attribute(POLES_ID()));
- aPointArrayAttr->setSize(2);
- aPointArrayAttr->setPnt(0, aClickedPoint);
- aPointArrayAttr->setPnt(1, aClickedPoint);
-
- // fill weights
- AttributeDoubleArrayPtr aWeightsArrayAttr = data()->realArray(WEIGHTS_ID());
- aWeightsArrayAttr->setSize(2);
- aWeightsArrayAttr->setValue(0, 1.0);
- aWeightsArrayAttr->setValue(1, 1.0);
-
- // fill reference attribute
- AttributeRefAttrListPtr aRefAttrList =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(attribute(REF_POLES_ID()));
- if (anAttribute) {
- if (!anAttribute->owner() || !anAttribute->owner()->data()->isValid()) {
- if (aCreatedFeature && anAttribute->id() == SketchPlugin_Point::COORD_ID())
- anAttribute = aCreatedFeature->attribute(SketchPlugin_Point::COORD_ID());
- }
- aRefAttrList->append(anAttribute);
- }
- }
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
- return std::string();
}
-// LCOV_EXCL_STOP
FeaturePtr SketchPlugin_MacroBSpline::createBSplineFeature()
{
+ if (myKnots.empty() || myMultiplicities.empty())
+ getAISObject(AISObjectPtr()); // fill B-spline parameters
+
FeaturePtr aBSpline = sketch()->addFeature(
myIsPeriodic ? SketchPlugin_BSplinePeriodic::ID() : SketchPlugin_BSpline::ID());
}
void SketchPlugin_MacroBSpline::createControlPolygon(FeaturePtr theBSpline,
+ bool thePeriodic,
std::list<FeaturePtr>& thePoles)
{
AttributePoint2DArrayPtr aPoles = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
// segments
for (int index = 1; index < aSize; ++index)
createAuxiliarySegment(aPoles, index - 1, index);
- if (myIsPeriodic) {
+ if (thePeriodic) {
// additional segment to close the control polygon
createAuxiliarySegment(aPoles, aSize - 1, 0);
}
// ========================== Auxiliary functions ===========================================
+void SketchPlugin_MacroBSpline::assignDefaultNameForAux(FeaturePtr theAuxFeature,
+ AttributePoint2DArrayPtr theBSplinePoles,
+ const int thePoleIndex1,
+ const int thePoleIndex2)
+{
+ FeaturePtr aBSpline = ModelAPI_Feature::feature(theBSplinePoles->owner());
+
+ std::wostringstream aName;
+ aName << aBSpline->name();
+ if (theAuxFeature->getKind() == SketchPlugin_Point::ID())
+ aName << "_" << Locale::Convert::toWString(theBSplinePoles->id()) << "_" << thePoleIndex1;
+ else
+ aName << "_segment_" << thePoleIndex1 << "_" << thePoleIndex2;
+
+ theAuxFeature->data()->setName(aName.str());
+ theAuxFeature->lastResult()->data()->setName(aName.str());
+}
+
FeaturePtr SketchPlugin_MacroBSpline::createAuxiliaryPole(AttributePoint2DArrayPtr theBSplinePoles,
const int thePoleIndex)
{
aCoord->setValue(aPole);
aPointFeature->execute();
-
- std::ostringstream aName;
- aName << aBSpline->name() << "_" << theBSplinePoles->id() << "_" << thePoleIndex;
- aPointFeature->data()->setName(aName.str());
- aPointFeature->lastResult()->data()->setName(aName.str());
+ assignDefaultNameForAux(aPointFeature, theBSplinePoles, thePoleIndex);
// internal constraint to keep position of the point
createInternalConstraint(aSketch, aCoord, theBSplinePoles, thePoleIndex);
aLineEnd->setValue(theBSplinePoles->pnt(thePoleIndex2));
aLineFeature->execute();
-
- std::ostringstream aName;
- aName << aBSpline->name() << "_segment_" << thePoleIndex1 << "_" << thePoleIndex2;
- aLineFeature->data()->setName(aName.str());
- aLineFeature->lastResult()->data()->setName(aName.str());
+ assignDefaultNameForAux(aLineFeature, theBSplinePoles, thePoleIndex1, thePoleIndex2);
// internal constraints to keep the segment position
createInternalConstraint(aSketch, aLineStart, theBSplinePoles, thePoleIndex1);