1 // Copyright (C) 2014-2023 CEA, EDF
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 <SketchPlugin_Projection.h>
22 #include <SketchPlugin_Arc.h>
23 #include <SketchPlugin_BSpline.h>
24 #include <SketchPlugin_BSplinePeriodic.h>
25 #include <SketchPlugin_Circle.h>
26 #include <SketchPlugin_Ellipse.h>
27 #include <SketchPlugin_EllipticArc.h>
28 #include <SketchPlugin_Line.h>
29 #include <SketchPlugin_Point.h>
30 #include <SketchPlugin_Sketch.h>
31 #include <SketchPlugin_ConstraintRigid.h>
33 #include <ModelAPI_AttributeRefAttr.h>
34 #include <ModelAPI_AttributeSelection.h>
35 #include <ModelAPI_AttributeDouble.h>
36 #include <ModelAPI_AttributeDoubleArray.h>
37 #include <ModelAPI_AttributeInteger.h>
38 #include <ModelAPI_AttributeString.h>
39 #include <ModelAPI_ResultConstruction.h>
40 #include <ModelAPI_Session.h>
41 #include <ModelAPI_Validator.h>
42 #include <ModelAPI_Tools.h>
43 #include <ModelAPI_Events.h>
45 #include <Events_Loop.h>
47 #include <GeomAPI_BSpline.h>
48 #include <GeomAPI_Circ.h>
49 #include <GeomAPI_Edge.h>
50 #include <GeomAPI_Ellipse.h>
51 #include <GeomAPI_Lin.h>
52 #include <GeomAPI_Pnt.h>
53 #include <GeomAPI_Pnt2d.h>
54 #include <GeomAPI_Vertex.h>
55 #include <GeomAlgoAPI_EdgeBuilder.h>
56 #include <GeomAlgoAPI_Projection.h>
57 #include <GeomDataAPI_Point2D.h>
58 #include <GeomDataAPI_Point2DArray.h>
62 static const double tolerance = 1.e-7;
63 static const std::string THE_KEEP_REF("true");
65 static bool isKeepReference(AttributeStringPtr theAttr)
67 return !theAttr || !theAttr->isInitialized() || theAttr->value() == THE_KEEP_REF;
71 SketchPlugin_Projection::SketchPlugin_Projection()
72 : SketchPlugin_SketchEntity(),
77 void SketchPlugin_Projection::initDerivedClassAttributes()
79 data()->addAttribute(EXTERNAL_FEATURE_ID(), ModelAPI_AttributeSelection::typeId());
80 data()->addAttribute(PROJECTED_FEATURE_ID(), ModelAPI_AttributeRefAttr::typeId());
81 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PROJECTED_FEATURE_ID());
82 data()->attribute(PROJECTED_FEATURE_ID())->setIsArgument(false);
84 data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
85 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
87 data()->addAttribute(INCLUDE_INTO_RESULT(), ModelAPI_AttributeBoolean::typeId());
89 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), AUXILIARY_ID());
92 void SketchPlugin_Projection::initDerivedClassAttributes2()
94 AttributePtr aKeepRefAttr =
95 data()->addAttribute(KEEP_REFERENCE_ID(), ModelAPI_AttributeString::typeId());
96 if (!aKeepRefAttr->isInitialized()) {
97 std::dynamic_pointer_cast<ModelAPI_AttributeString>(aKeepRefAttr)->setValue(THE_KEEP_REF);
100 data()->addAttribute(MAKE_FIXED(), ModelAPI_AttributeBoolean::typeId());
101 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), MAKE_FIXED());
103 data()->addAttribute(FIXED_CONSTRAINT_ID(), ModelAPI_AttributeReference::typeId());
104 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FIXED_CONSTRAINT_ID());
105 data()->attribute(FIXED_CONSTRAINT_ID())->setIsArgument(false);
108 void SketchPlugin_Projection::execute()
110 AttributeRefAttrPtr aRefAttr = data()->refattr(PROJECTED_FEATURE_ID());
111 if (!aRefAttr || !aRefAttr->isInitialized())
113 FeaturePtr aProjection = ModelAPI_Feature::feature(aRefAttr->object());
115 if (isKeepReference(string(KEEP_REFERENCE_ID())) && !lastResult().get()) {
116 bool hasProjResult = aProjection->lastResult().get() != NULL;
117 ResultConstructionPtr aConstr = document()->createConstruction(data());
119 aConstr->setShape(aProjection->lastResult()->shape());
120 aConstr->setIsInHistory(false);
121 aConstr->setDisplayed(false);
125 aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape());
128 // is sketch plane is changed (issue 1791), attribute of projection is not changed, but
129 // projection must be fully recomputed
130 computeProjection(EXTERNAL_FEATURE_ID());
133 bool SketchPlugin_Projection::isMacro() const
135 if (!data() || !data()->isValid())
138 AttributeStringPtr aKeepRefAttr =
139 const_cast<SketchPlugin_Projection*>(this)->string(KEEP_REFERENCE_ID());
140 return !isKeepReference(aKeepRefAttr);
143 void SketchPlugin_Projection::attributeChanged(const std::string& theID)
145 if ((theID == EXTERNAL_FEATURE_ID() || theID == EXTERNAL_ID()) && !myIsComputing) {
146 myIsComputing = true;
147 computeProjection(theID);
148 myIsComputing = false;
152 static const std::set<std::string>& POINT_PROJECTION()
154 static std::set<std::string> aProj;
156 aProj.insert(SketchPlugin_Point::ID());
160 static const std::set<std::string>& LINE_PROJECTION()
162 static std::set<std::string> aProj;
164 aProj.insert(SketchPlugin_Line::ID());
168 static const std::set<std::string>& CIRCLE_ELLIPSE_PROJECTION()
170 static std::set<std::string> aProj;
172 aProj.insert(SketchPlugin_Circle::ID());
173 aProj.insert(SketchPlugin_Ellipse::ID());
178 static const std::set<std::string>& ARC_PROJECTION()
180 static std::set<std::string> aProj;
182 aProj.insert(SketchPlugin_Arc::ID());
183 aProj.insert(SketchPlugin_EllipticArc::ID());
188 static const std::set<std::string>& BSPLINE_PROJECTION()
190 static std::set<std::string> aProj;
192 aProj.insert(SketchPlugin_BSpline::ID());
193 aProj.insert(SketchPlugin_BSplinePeriodic::ID());
199 static const std::set<std::string>& possibleProjectionTypes(GeomEdgePtr theEdge,
200 GeomVertexPtr theVertex)
203 return POINT_PROJECTION();
205 if (theEdge->isLine())
206 return LINE_PROJECTION();
207 else if (theEdge->isCircle() || theEdge->isArc() || theEdge->isEllipse()) {
208 if (theEdge->isClosed())
209 return CIRCLE_ELLIPSE_PROJECTION();
211 return ARC_PROJECTION();
214 return BSPLINE_PROJECTION();
216 static const std::set<std::string> DUMMY;
220 void SketchPlugin_Projection::computeProjection(const std::string& theID)
222 AttributeSelectionPtr aExtFeature =
223 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(attribute(EXTERNAL_FEATURE_ID()));
227 GeomVertexPtr aVertex;
229 aShape = aExtFeature->value();
230 if (!aShape && aExtFeature->context())
231 aShape = aExtFeature->context()->shape();
233 if (aShape->isEdge())
234 anEdge = GeomEdgePtr(new GeomAPI_Edge(aShape));
235 else if (aShape->isVertex())
236 aVertex = GeomVertexPtr(new GeomAPI_Vertex(aShape));
238 if (!anEdge && !aVertex)
241 const std::set<std::string>& aProjType = possibleProjectionTypes(anEdge, aVertex);
243 AttributeRefAttrPtr aRefAttr = data()->refattr(PROJECTED_FEATURE_ID());
244 FeaturePtr aProjection;
245 if (aRefAttr && aRefAttr->isInitialized())
246 aProjection = ModelAPI_Feature::feature(aRefAttr->object());
248 // if the type of feature differs with already selected, remove it and create once again
249 bool isRebuild = rebuildProjectedFeature(aProjection, aProjType);
251 ResultConstructionPtr aResult =
252 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(lastResult());
253 if (!isRebuild && aResult && aResult->shape() && theID == EXTERNAL_FEATURE_ID()) {
254 aResult->setShape(std::shared_ptr<GeomAPI_Edge>());
256 aProjection->selection(EXTERNAL_ID())->setValue(ResultPtr(), GeomShapePtr());
259 keepCurrentFeature();
261 bool isProjected = false;
263 isProjected = projectPoint(aProjection, aVertex->point());
265 isProjected = projectEdge(aProjection, anEdge);
268 return; // projection is not computed, stop processing
270 bool keepBackRef = isKeepReference(string(KEEP_REFERENCE_ID()));
272 aProjection->boolean(COPY_ID())->setValue(keepBackRef);
273 aProjection->execute();
274 aRefAttr->setObject(aProjection);
276 restoreCurrentFeature();
278 AttributeBooleanPtr aMakeFixedAttr = boolean(MAKE_FIXED());
279 bool isMakeFixed = aMakeFixedAttr && aMakeFixedAttr->isInitialized() && aMakeFixedAttr->value();
281 AttributeReferencePtr aFixedConstrAttr = reference(FIXED_CONSTRAINT_ID());
282 FeaturePtr aFixedConstraint;
283 if (aFixedConstrAttr && aFixedConstrAttr->isInitialized())
284 aFixedConstraint = ModelAPI_Feature::feature(aFixedConstrAttr->value());
287 if (theID == EXTERNAL_FEATURE_ID()) {
288 selection(EXTERNAL_ID())->selectValue(aExtFeature);
291 aResult->setShape(aProjection->lastResult()->shape());
293 GeomShapePtr anEmptyVal;
294 aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), anEmptyVal);
298 else if (isMakeFixed) {
299 // fix the projected entity with the Fixed constraint
300 if (!aFixedConstraint)
301 aFixedConstraint = sketch()->addFeature(SketchPlugin_ConstraintRigid::ID());
302 aFixedConstraint->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject(
303 aProjection->lastResult());
307 // remove Fixed constraint in case of redundance
308 if (aFixedConstraint && (keepBackRef || !isMakeFixed)) {
309 document()->removeFeature(aFixedConstraint);
310 aFixedConstraint = FeaturePtr();
312 aFixedConstrAttr->setValue(aFixedConstraint);
314 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_VISUAL_ATTRIBUTES);
315 ModelAPI_EventCreator::get()->sendUpdated(aProjection, anEvent, false);
318 bool SketchPlugin_Projection::rebuildProjectedFeature(
319 FeaturePtr& theProjection,
320 const std::set<std::string>& theSupportedTypes,
321 const std::string& theRequestedFeature)
323 bool isRebuild = false;
325 (theSupportedTypes.find(theProjection->getKind()) == theSupportedTypes.end() ||
326 (!theRequestedFeature.empty() && theProjection->getKind() != theRequestedFeature))) {
327 DocumentPtr aDoc = sketch()->document();
329 AttributeRefAttrPtr aRefAttr = data()->refattr(PROJECTED_FEATURE_ID());
330 aRefAttr->setObject(data()->owner()); // to not remove of this remove reference to aProjection
331 std::set<FeaturePtr> aFeaturesToBeRemoved;
332 aFeaturesToBeRemoved.insert(theProjection);
333 ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToBeRemoved);
334 theProjection = FeaturePtr();
335 aRefAttr->setObject(theProjection);
339 if (!theProjection && !theRequestedFeature.empty())
340 theProjection = sketch()->addFeature(theRequestedFeature);
344 bool SketchPlugin_Projection::projectPoint(FeaturePtr& theProjection, const GeomPointPtr& thePoint)
346 std::shared_ptr<GeomAPI_Pln> aSketchPlane = sketch()->plane();
348 std::shared_ptr<GeomAPI_Pnt> aPrjPnt = aSketchPlane->project(thePoint);
349 std::shared_ptr<GeomAPI_Pnt2d> aPntInSketch = sketch()->to2D(aPrjPnt);
351 rebuildProjectedFeature(theProjection, POINT_PROJECTION(), SketchPlugin_Point::ID());
353 // update coordinates of projection
354 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
355 theProjection->attribute(SketchPlugin_Point::COORD_ID()))->setValue(aPntInSketch);
359 bool SketchPlugin_Projection::projectSegment(FeaturePtr& theProjection, const GeomEdgePtr& theEdge)
361 std::shared_ptr<GeomAPI_Pln> aSketchPlane = sketch()->plane();
363 std::shared_ptr<GeomAPI_Pnt> aFirst = aSketchPlane->project(theEdge->firstPoint());
364 std::shared_ptr<GeomAPI_Pnt> aLast = aSketchPlane->project(theEdge->lastPoint());
366 std::shared_ptr<GeomAPI_Pnt2d> aFirstInSketch = sketch()->to2D(aFirst);
367 std::shared_ptr<GeomAPI_Pnt2d> aLastInSketch = sketch()->to2D(aLast);
368 if (aFirstInSketch->distance(aLastInSketch) < tolerance)
369 return false; // line is semi-orthogonal to the sketch plane
371 rebuildProjectedFeature(theProjection, LINE_PROJECTION(), SketchPlugin_Line::ID());
373 // update attributes of projection
374 std::shared_ptr<GeomDataAPI_Point2D> aStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
375 theProjection->attribute(SketchPlugin_Line::START_ID()));
376 std::shared_ptr<GeomDataAPI_Point2D> aEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
377 theProjection->attribute(SketchPlugin_Line::END_ID()));
378 aStartPnt->setValue(aFirstInSketch);
379 aEndPnt->setValue(aLastInSketch);
384 bool SketchPlugin_Projection::projectEdge(FeaturePtr& theProjection, const GeomEdgePtr& theEdge)
386 if (theEdge->isLine())
387 return projectSegment(theProjection, theEdge);
389 std::shared_ptr<GeomAPI_Pln> aSketchPlane = sketch()->plane();
391 GeomAlgoAPI_Projection aProjAlgo(aSketchPlane);
392 GeomCurvePtr aProjectedCurve = aProjAlgo.project(theEdge);
395 if (aProjectedCurve->isCircle()) {
396 if (aProjectedCurve->isTrimmed()) {
397 // ARC is a projection
398 isOk = fillArc(theProjection, aProjectedCurve, aSketchPlane, theEdge);
401 // CIRCLE is a projection
402 isOk = fillCircle(theProjection, aProjectedCurve, aSketchPlane);
405 else if (aProjectedCurve->isEllipse()) {
406 if (aProjectedCurve->isTrimmed()) {
407 // ELLIPTIC ARC is a projection
408 isOk = fillEllipticArc(theProjection, aProjectedCurve, aSketchPlane, theEdge);
411 // ELLIPSE is a projection
412 isOk = fillEllipse(theProjection, aProjectedCurve, aSketchPlane);
416 isOk = fillBSpline(theProjection, aProjectedCurve, aSketchPlane);
421 bool SketchPlugin_Projection::fillArc(FeaturePtr& theProjection,
422 const GeomCurvePtr& theArc,
423 const GeomPlanePtr& thePlane,
424 const GeomEdgePtr& theOriginalEdge)
426 rebuildProjectedFeature(theProjection, ARC_PROJECTION(), SketchPlugin_Arc::ID());
428 GeomAPI_Circ aCircle(theArc);
430 double aNormalsDot = aCircle.normal()->dot(thePlane->direction());
431 if (fabs(fabs(aNormalsDot) - 1.0) > tolerance)
432 return false; // arc is not in the plane, parallel to the sketch plane
434 bool isInversed = aNormalsDot < 0.;
436 GeomCirclePtr anOriginalCircle = theOriginalEdge->circle();
437 if (anOriginalCircle) {
438 double aCirclesDot = anOriginalCircle->normal()->dot(aCircle.normal());
439 if (aCirclesDot < 0.)
440 isInversed = !isInversed;
443 GeomPointPtr aCenter = thePlane->project(aCircle.center());
444 GeomPnt2dPtr aCenterInSketch = sketch()->to2D(aCenter);
446 GeomPointPtr aFirst = theArc->getPoint(theArc->startParam());
447 GeomPnt2dPtr aFirstInSketch = sketch()->to2D(thePlane->project(aFirst));
449 GeomPointPtr aLast = theArc->getPoint(theArc->endParam());
450 GeomPnt2dPtr aLastInSketch = sketch()->to2D(thePlane->project(aLast));
452 bool aWasBlocked = theProjection->data()->blockSendAttributeUpdated(true);
454 // update attributes of projection
455 std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
456 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
457 theProjection->attribute(SketchPlugin_Arc::CENTER_ID()));
458 std::shared_ptr<GeomDataAPI_Point2D> aStartPnt =
459 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
460 theProjection->attribute(SketchPlugin_Arc::START_ID()));
461 std::shared_ptr<GeomDataAPI_Point2D> aEndPnt =
462 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
463 theProjection->attribute(SketchPlugin_Arc::END_ID()));
464 aStartPnt->setValue(aFirstInSketch);
465 aEndPnt->setValue(aLastInSketch);
466 aCenterPnt->setValue(aCenterInSketch);
467 theProjection->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(isInversed);
469 theProjection->data()->blockSendAttributeUpdated(aWasBlocked);
473 bool SketchPlugin_Projection::fillCircle(FeaturePtr& theProjection,
474 const GeomCurvePtr& theCircle,
475 const GeomPlanePtr& thePlane)
477 rebuildProjectedFeature(theProjection, CIRCLE_ELLIPSE_PROJECTION(), SketchPlugin_Circle::ID());
479 GeomAPI_Circ aCircle(theCircle);
480 GeomPointPtr aCenter = thePlane->project(aCircle.center());
481 GeomPnt2dPtr aCenterInSketch = sketch()->to2D(aCenter);
483 // update attributes of projection
484 std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
485 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
486 theProjection->attribute(SketchPlugin_Circle::CENTER_ID()));
487 aCenterPnt->setValue(aCenterInSketch);
488 theProjection->real(SketchPlugin_Circle::RADIUS_ID())->setValue(aCircle.radius());
492 bool SketchPlugin_Projection::fillEllipse(FeaturePtr& theProjection,
493 const GeomCurvePtr& theEllipse,
494 const GeomPlanePtr& thePlane)
496 rebuildProjectedFeature(theProjection, CIRCLE_ELLIPSE_PROJECTION(), SketchPlugin_Ellipse::ID());
498 GeomAPI_Ellipse anEllipse(theEllipse);
499 GeomPointPtr aCenter = thePlane->project(anEllipse.center());
500 GeomPnt2dPtr aCenterInSketch = sketch()->to2D(aCenter);
501 GeomPointPtr aFocus = thePlane->project(anEllipse.firstFocus());
502 GeomPnt2dPtr aFocusInSketch = sketch()->to2D(aFocus);
504 // update attributes of projection
505 std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
506 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
507 theProjection->attribute(SketchPlugin_Ellipse::CENTER_ID()));
508 aCenterPnt->setValue(aCenterInSketch);
509 std::shared_ptr<GeomDataAPI_Point2D> aFocusPnt =
510 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
511 theProjection->attribute(SketchPlugin_Ellipse::FIRST_FOCUS_ID()));
512 aFocusPnt->setValue(aFocusInSketch);
513 theProjection->real(SketchPlugin_Ellipse::MINOR_RADIUS_ID())->setValue(anEllipse.minorRadius());
517 bool SketchPlugin_Projection::fillEllipticArc(FeaturePtr& theProjection,
518 const GeomCurvePtr& theEllipticArc,
519 const GeomPlanePtr& thePlane,
520 const GeomEdgePtr& theOriginalEdge)
522 rebuildProjectedFeature(theProjection, ARC_PROJECTION(), SketchPlugin_EllipticArc::ID());
524 GeomAPI_Ellipse anEllipse(theEllipticArc);
526 double aNormalsDot = anEllipse.normal()->dot(thePlane->direction());
527 if (fabs(fabs(aNormalsDot) - 1.0) > tolerance)
528 return false; // arc is not in the plane, parallel to the sketch plane
530 bool isInversed = aNormalsDot < 0.;
532 GeomEllipsePtr anOriginalEllipse = theOriginalEdge->ellipse();
533 if (anOriginalEllipse) {
534 double anEllipsesDot = anOriginalEllipse->normal()->dot(anEllipse.normal());
535 if (anEllipsesDot < 0.)
536 isInversed = !isInversed;
539 GeomPointPtr aCenter = thePlane->project(anEllipse.center());
540 GeomPnt2dPtr aCenterInSketch = sketch()->to2D(aCenter);
541 GeomPointPtr aFocus = thePlane->project(anEllipse.firstFocus());
542 GeomPnt2dPtr aFocusInSketch = sketch()->to2D(aFocus);
544 GeomPointPtr aFirst = theEllipticArc->getPoint(theEllipticArc->startParam());
545 GeomPnt2dPtr aFirstInSketch = sketch()->to2D(thePlane->project(aFirst));
546 GeomPointPtr aLast = theEllipticArc->getPoint(theEllipticArc->endParam());
547 GeomPnt2dPtr aLastInSketch = sketch()->to2D(thePlane->project(aLast));
549 bool aWasBlocked = theProjection->data()->blockSendAttributeUpdated(true);
551 // update attributes of projection
552 std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
553 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
554 theProjection->attribute(SketchPlugin_EllipticArc::CENTER_ID()));
555 std::shared_ptr<GeomDataAPI_Point2D> aFocusPnt =
556 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
557 theProjection->attribute(SketchPlugin_EllipticArc::FIRST_FOCUS_ID()));
558 std::shared_ptr<GeomDataAPI_Point2D> aStartPnt =
559 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
560 theProjection->attribute(SketchPlugin_EllipticArc::START_POINT_ID()));
561 std::shared_ptr<GeomDataAPI_Point2D> aEndPnt =
562 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
563 theProjection->attribute(SketchPlugin_EllipticArc::END_POINT_ID()));
564 aStartPnt->setValue(aFirstInSketch);
565 aEndPnt->setValue(aLastInSketch);
566 aCenterPnt->setValue(aCenterInSketch);
567 aFocusPnt->setValue(aFocusInSketch);
568 theProjection->boolean(SketchPlugin_EllipticArc::REVERSED_ID())->setValue(isInversed);
570 theProjection->data()->blockSendAttributeUpdated(aWasBlocked);
574 bool SketchPlugin_Projection::fillBSpline(FeaturePtr& theProjection,
575 const GeomCurvePtr& theCurve,
576 const GeomPlanePtr& /*thePlane*/)
578 GeomAPI_BSpline aBSpline(theCurve);
580 rebuildProjectedFeature(theProjection, BSPLINE_PROJECTION(),
581 aBSpline.isPeriodic() ? SketchPlugin_BSplinePeriodic::ID() : SketchPlugin_BSpline::ID());
583 theProjection->integer(SketchPlugin_BSpline::DEGREE_ID())->setValue(aBSpline.degree());
585 AttributePoint2DArrayPtr aPolesAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
586 theProjection->attribute(SketchPlugin_BSpline::POLES_ID()));
587 std::list<GeomPointPtr> aPoles = aBSpline.poles();
588 aPolesAttr->setSize((int)aPoles.size());
589 std::list<GeomPointPtr>::iterator anIt = aPoles.begin();
590 for (int anIndex = 0; anIt != aPoles.end(); ++anIt, ++anIndex) {
591 GeomPnt2dPtr aPoleInSketch = sketch()->to2D(*anIt);
592 aPolesAttr->setPnt(anIndex, aPoleInSketch);
595 AttributeDoubleArrayPtr aWeightsAttr =
596 theProjection->data()->realArray(SketchPlugin_BSpline::WEIGHTS_ID());
597 std::list<double> aWeights = aBSpline.weights();
598 if (aWeights.empty()) { // rational B-spline
599 int aSize = (int)aPoles.size();
600 aWeightsAttr->setSize(aSize);
601 for (int anIndex = 0; anIndex < aSize; ++anIndex)
602 aWeightsAttr->setValue(anIndex, 1.0);
604 else { // non-rational B-spline
605 aWeightsAttr->setSize((int)aWeights.size());
606 std::list<double>::iterator aWIt = aWeights.begin();
607 for (int anIndex = 0; aWIt != aWeights.end(); ++aWIt, ++anIndex)
608 aWeightsAttr->setValue(anIndex, *aWIt);
611 AttributeDoubleArrayPtr aKnotsAttr =
612 theProjection->data()->realArray(SketchPlugin_BSpline::KNOTS_ID());
613 std::list<double> aKnots = aBSpline.knots();
614 int aSize = (int)aKnots.size();
615 aKnotsAttr->setSize(aSize);
616 std::list<double>::iterator aKIt = aKnots.begin();
617 for (int index = 0; index < aSize; ++index, ++aKIt)
618 aKnotsAttr->setValue(index, *aKIt);
620 AttributeIntArrayPtr aMultsAttr =
621 theProjection->data()->intArray(SketchPlugin_BSpline::MULTS_ID());
622 std::list<int> aMultiplicities = aBSpline.mults();
623 aSize = (int)aMultiplicities.size();
624 aMultsAttr->setSize(aSize);
625 std::list<int>::iterator aMIt = aMultiplicities.begin();
626 for (int index = 0; index < aSize; ++index, ++aMIt)
627 aMultsAttr->setValue(index, *aMIt);