Salome HOME
Merge branch 'master' into occ/bsplines
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Projection.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
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_Projection.h>
21
22 #include <SketchPlugin_Arc.h>
23 #include <SketchPlugin_BSpline.h>
24 #include <SketchPlugin_Circle.h>
25 #include <SketchPlugin_Ellipse.h>
26 #include <SketchPlugin_EllipticArc.h>
27 #include <SketchPlugin_Line.h>
28 #include <SketchPlugin_Point.h>
29 #include <SketchPlugin_Sketch.h>
30 #include <SketchPlugin_ConstraintRigid.h>
31
32 #include <ModelAPI_AttributeRefAttr.h>
33 #include <ModelAPI_AttributeSelection.h>
34 #include <ModelAPI_AttributeDouble.h>
35 #include <ModelAPI_AttributeDoubleArray.h>
36 #include <ModelAPI_AttributeInteger.h>
37 #include <ModelAPI_ResultConstruction.h>
38 #include <ModelAPI_Session.h>
39 #include <ModelAPI_Validator.h>
40 #include <ModelAPI_Tools.h>
41 #include <ModelAPI_Events.h>
42
43 #include <Events_Loop.h>
44
45 #include <GeomAPI_BSpline.h>
46 #include <GeomAPI_Circ.h>
47 #include <GeomAPI_Edge.h>
48 #include <GeomAPI_Ellipse.h>
49 #include <GeomAPI_Lin.h>
50 #include <GeomAPI_Pnt.h>
51 #include <GeomAPI_Pnt2d.h>
52 #include <GeomAPI_Vertex.h>
53 #include <GeomAlgoAPI_EdgeBuilder.h>
54 #include <GeomAlgoAPI_Projection.h>
55 #include <GeomDataAPI_Point2D.h>
56 #include <GeomDataAPI_Point2DArray.h>
57
58 #include <cmath>
59
60 static const double tolerance = 1.e-7;
61
62
63 SketchPlugin_Projection::SketchPlugin_Projection()
64     : SketchPlugin_SketchEntity(),
65       myIsComputing(false)
66 {
67 }
68
69 void SketchPlugin_Projection::initDerivedClassAttributes()
70 {
71   data()->addAttribute(EXTERNAL_FEATURE_ID(), ModelAPI_AttributeSelection::typeId());
72   data()->addAttribute(PROJECTED_FEATURE_ID(), ModelAPI_AttributeRefAttr::typeId());
73   data()->attribute(PROJECTED_FEATURE_ID())->setIsArgument(false);
74
75   data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
76   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
77
78   data()->addAttribute(INCLUDE_INTO_RESULT(), ModelAPI_AttributeBoolean::typeId());
79
80   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), AUXILIARY_ID());
81 }
82
83 void SketchPlugin_Projection::execute()
84 {
85   AttributeRefAttrPtr aRefAttr = data()->refattr(PROJECTED_FEATURE_ID());
86   if (!aRefAttr || !aRefAttr->isInitialized())
87     return;
88   FeaturePtr aProjection = ModelAPI_Feature::feature(aRefAttr->object());
89
90   if (!lastResult().get()) {
91     bool hasProjResult = aProjection->lastResult().get() != NULL;
92     ResultConstructionPtr aConstr = document()->createConstruction(data());
93     if (hasProjResult)
94       aConstr->setShape(aProjection->lastResult()->shape());
95     aConstr->setIsInHistory(false);
96     aConstr->setDisplayed(false);
97     setResult(aConstr);
98
99     if (hasProjResult)
100       aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape());
101   }
102
103   // is sketch plane is changed (issue 1791), attribute of projection is not changed, but
104   // projection must be fully recomputed
105   computeProjection(EXTERNAL_FEATURE_ID());
106 }
107
108 void SketchPlugin_Projection::attributeChanged(const std::string& theID)
109 {
110   if ((theID == EXTERNAL_FEATURE_ID() || theID == EXTERNAL_ID()) && !myIsComputing) {
111     myIsComputing = true;
112     computeProjection(theID);
113     myIsComputing = false;
114   }
115 }
116
117 static const std::set<std::string>& POINT_PROJECTION()
118 {
119   static std::set<std::string> aProj;
120   if (aProj.empty())
121     aProj.insert(SketchPlugin_Point::ID());
122   return aProj;
123 }
124
125 static const std::set<std::string>& LINE_PROJECTION()
126 {
127   static std::set<std::string> aProj;
128   if (aProj.empty())
129     aProj.insert(SketchPlugin_Line::ID());
130   return aProj;
131 }
132
133 static const std::set<std::string>& CIRCLE_ELLIPSE_PROJECTION()
134 {
135   static std::set<std::string> aProj;
136   if (aProj.empty()) {
137     aProj.insert(SketchPlugin_Circle::ID());
138     aProj.insert(SketchPlugin_Ellipse::ID());
139   }
140   return aProj;
141 }
142
143 static const std::set<std::string>& ARC_PROJECTION()
144 {
145   static std::set<std::string> aProj;
146   if (aProj.empty()) {
147     aProj.insert(SketchPlugin_Arc::ID());
148     aProj.insert(SketchPlugin_EllipticArc::ID());
149   }
150   return aProj;
151 }
152
153 static const std::set<std::string>& BSPLINE_PROJECTION()
154 {
155   static std::set<std::string> aProj;
156   if (aProj.empty())
157     aProj.insert(SketchPlugin_BSpline::ID());
158   return aProj;
159 }
160
161
162 static const std::set<std::string>& possibleProjectionTypes(GeomEdgePtr theEdge,
163                                                             GeomVertexPtr theVertex)
164 {
165   if (theVertex)
166     return POINT_PROJECTION();
167   if (theEdge) {
168     if (theEdge->isLine())
169       return LINE_PROJECTION();
170     else if (theEdge->isCircle() || theEdge->isArc() || theEdge->isEllipse()) {
171       if (theEdge->isClosed())
172         return CIRCLE_ELLIPSE_PROJECTION();
173       else
174         return ARC_PROJECTION();
175     }
176     else
177       return BSPLINE_PROJECTION();
178   }
179   static const std::set<std::string> DUMMY;
180   return DUMMY;
181 }
182
183 void SketchPlugin_Projection::computeProjection(const std::string& theID)
184 {
185   AttributeSelectionPtr aExtFeature =
186       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(attribute(EXTERNAL_FEATURE_ID()));
187
188   GeomShapePtr aShape;
189   GeomEdgePtr anEdge;
190   GeomVertexPtr aVertex;
191   if (aExtFeature)
192     aShape = aExtFeature->value();
193   if (!aShape && aExtFeature->context())
194     aShape = aExtFeature->context()->shape();
195   if (aShape) {
196     if (aShape->isEdge())
197       anEdge = GeomEdgePtr(new GeomAPI_Edge(aShape));
198     else if (aShape->isVertex())
199       aVertex = GeomVertexPtr(new GeomAPI_Vertex(aShape));
200   }
201   if (!anEdge && !aVertex)
202     return;
203
204   const std::set<std::string>& aProjType = possibleProjectionTypes(anEdge, aVertex);
205
206   AttributeRefAttrPtr aRefAttr = data()->refattr(PROJECTED_FEATURE_ID());
207   FeaturePtr aProjection;
208   if (aRefAttr && aRefAttr->isInitialized())
209     aProjection = ModelAPI_Feature::feature(aRefAttr->object());
210
211   // if the type of feature differs with already selected, remove it and create once again
212   bool isRebuild = rebuildProjectedFeature(aProjection, aProjType);
213
214   ResultConstructionPtr aResult =
215       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(lastResult());
216   if (!isRebuild && aResult && aResult->shape() && theID == EXTERNAL_FEATURE_ID()) {
217     aResult->setShape(std::shared_ptr<GeomAPI_Edge>());
218     if (aProjection)
219       aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape());
220   }
221
222   keepCurrentFeature();
223
224   bool isProjected = false;
225   if (aVertex)
226     isProjected = projectPoint(aProjection, aVertex->point());
227   else
228     isProjected = projectEdge(aProjection, anEdge);
229
230   if (!isProjected)
231     return; // projection is not computed, stop processing
232
233   aProjection->boolean(COPY_ID())->setValue(true);
234   aProjection->execute();
235   aRefAttr->setObject(aProjection);
236
237   restoreCurrentFeature();
238
239   if (theID == EXTERNAL_FEATURE_ID()) {
240     selection(EXTERNAL_ID())->selectValue(aExtFeature);
241
242     if (aResult) {
243       aResult->setShape(aProjection->lastResult()->shape());
244       setResult(aResult);
245       GeomShapePtr anEmptyVal;
246       aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), anEmptyVal);
247
248       static const Events_ID anEvent = Events_Loop::eventByName(EVENT_VISUAL_ATTRIBUTES);
249       ModelAPI_EventCreator::get()->sendUpdated(aProjection, anEvent, false);
250     }
251   }
252 }
253
254 bool SketchPlugin_Projection::rebuildProjectedFeature(
255     FeaturePtr& theProjection,
256     const std::set<std::string>& theSupportedTypes,
257     const std::string& theRequestedFeature)
258 {
259   bool isRebuild = false;
260   if (theProjection &&
261       (theSupportedTypes.find(theProjection->getKind()) == theSupportedTypes.end() ||
262       (!theRequestedFeature.empty() && theProjection->getKind() != theRequestedFeature))) {
263     DocumentPtr aDoc = sketch()->document();
264
265     AttributeRefAttrPtr aRefAttr = data()->refattr(PROJECTED_FEATURE_ID());
266     aRefAttr->setObject(data()->owner()); // to not remove of this remove reference to aProjection
267     std::set<FeaturePtr> aFeaturesToBeRemoved;
268     aFeaturesToBeRemoved.insert(theProjection);
269     ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToBeRemoved);
270     theProjection = FeaturePtr();
271     aRefAttr->setObject(theProjection);
272     isRebuild = true;
273   }
274
275   if (!theProjection && !theRequestedFeature.empty())
276     theProjection = sketch()->addFeature(theRequestedFeature);
277   return isRebuild;
278 }
279
280 bool SketchPlugin_Projection::projectPoint(FeaturePtr& theProjection, const GeomPointPtr& thePoint)
281 {
282   std::shared_ptr<GeomAPI_Pln> aSketchPlane = sketch()->plane();
283
284   std::shared_ptr<GeomAPI_Pnt> aPrjPnt = aSketchPlane->project(thePoint);
285   std::shared_ptr<GeomAPI_Pnt2d> aPntInSketch = sketch()->to2D(aPrjPnt);
286
287   rebuildProjectedFeature(theProjection, POINT_PROJECTION(), SketchPlugin_Point::ID());
288
289   // update coordinates of projection
290   std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
291       theProjection->attribute(SketchPlugin_Point::COORD_ID()))->setValue(aPntInSketch);
292   return true;
293 }
294
295 bool SketchPlugin_Projection::projectSegment(FeaturePtr& theProjection, const GeomEdgePtr& theEdge)
296 {
297   std::shared_ptr<GeomAPI_Pln> aSketchPlane = sketch()->plane();
298
299   std::shared_ptr<GeomAPI_Pnt> aFirst = aSketchPlane->project(theEdge->firstPoint());
300   std::shared_ptr<GeomAPI_Pnt> aLast = aSketchPlane->project(theEdge->lastPoint());
301
302   std::shared_ptr<GeomAPI_Pnt2d> aFirstInSketch = sketch()->to2D(aFirst);
303   std::shared_ptr<GeomAPI_Pnt2d> aLastInSketch = sketch()->to2D(aLast);
304   if (aFirstInSketch->distance(aLastInSketch) < tolerance)
305     return false; // line is semi-orthogonal to the sketch plane
306
307   rebuildProjectedFeature(theProjection, LINE_PROJECTION(), SketchPlugin_Line::ID());
308
309   // update attributes of projection
310   std::shared_ptr<GeomDataAPI_Point2D> aStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
311       theProjection->attribute(SketchPlugin_Line::START_ID()));
312   std::shared_ptr<GeomDataAPI_Point2D> aEndPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
313       theProjection->attribute(SketchPlugin_Line::END_ID()));
314   aStartPnt->setValue(aFirstInSketch);
315   aEndPnt->setValue(aLastInSketch);
316
317   return true;
318 }
319
320 bool SketchPlugin_Projection::projectEdge(FeaturePtr& theProjection, const GeomEdgePtr& theEdge)
321 {
322   if (theEdge->isLine())
323     return projectSegment(theProjection, theEdge);
324
325   std::shared_ptr<GeomAPI_Pln> aSketchPlane = sketch()->plane();
326
327   GeomAlgoAPI_Projection aProjAlgo(aSketchPlane);
328   GeomCurvePtr aProjectedCurve = aProjAlgo.project(theEdge);
329
330   bool isOk = false;
331   if (aProjectedCurve->isCircle()) {
332     if (aProjectedCurve->isTrimmed()) {
333       // ARC is a projection
334       isOk = fillArc(theProjection, aProjectedCurve, aSketchPlane);
335     }
336     else {
337       // CIRCLE is a projection
338       isOk = fillCircle(theProjection, aProjectedCurve, aSketchPlane);
339     }
340   }
341   else if (aProjectedCurve->isEllipse()) {
342     if (aProjectedCurve->isTrimmed()) {
343       // ELLIPTIC ARC is a projection
344       isOk = fillEllipticArc(theProjection, aProjectedCurve, aSketchPlane);
345     }
346     else {
347       // ELLIPSE is a projection
348       isOk = fillEllipse(theProjection, aProjectedCurve, aSketchPlane);
349     }
350   }
351   else
352     isOk = fillBSpline(theProjection, aProjectedCurve, aSketchPlane);
353
354   return isOk;
355 }
356
357 bool SketchPlugin_Projection::fillArc(FeaturePtr& theProjection,
358                                       const GeomCurvePtr& theArc,
359                                       const GeomPlanePtr& thePlane)
360 {
361   rebuildProjectedFeature(theProjection, ARC_PROJECTION(), SketchPlugin_Arc::ID());
362
363   GeomAPI_Circ aCircle(theArc);
364
365   double aNormalsDot = aCircle.normal()->dot(thePlane->direction());
366   if (fabs(fabs(aNormalsDot) - 1.0) > tolerance)
367     return false; // arc is not in the plane, parallel to the sketch plane
368
369   bool isInversed = aNormalsDot < 0.;
370
371   GeomPointPtr aCenter = thePlane->project(aCircle.center());
372   GeomPnt2dPtr aCenterInSketch = sketch()->to2D(aCenter);
373
374   GeomPointPtr aFirst = theArc->getPoint(theArc->startParam());
375   GeomPnt2dPtr aFirstInSketch = sketch()->to2D(thePlane->project(aFirst));
376
377   GeomPointPtr aLast = theArc->getPoint(theArc->endParam());
378   GeomPnt2dPtr aLastInSketch = sketch()->to2D(thePlane->project(aLast));
379
380   bool aWasBlocked = theProjection->data()->blockSendAttributeUpdated(true);
381
382   // update attributes of projection
383   std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
384       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
385       theProjection->attribute(SketchPlugin_Arc::CENTER_ID()));
386   std::shared_ptr<GeomDataAPI_Point2D> aStartPnt =
387       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
388       theProjection->attribute(SketchPlugin_Arc::START_ID()));
389   std::shared_ptr<GeomDataAPI_Point2D> aEndPnt =
390       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
391       theProjection->attribute(SketchPlugin_Arc::END_ID()));
392   aStartPnt->setValue(aFirstInSketch);
393   aEndPnt->setValue(aLastInSketch);
394   aCenterPnt->setValue(aCenterInSketch);
395   theProjection->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(isInversed);
396
397   theProjection->data()->blockSendAttributeUpdated(aWasBlocked);
398   return true;
399 }
400
401 bool SketchPlugin_Projection::fillCircle(FeaturePtr& theProjection,
402                                          const GeomCurvePtr& theCircle,
403                                          const GeomPlanePtr& thePlane)
404 {
405   rebuildProjectedFeature(theProjection, CIRCLE_ELLIPSE_PROJECTION(), SketchPlugin_Circle::ID());
406
407   GeomAPI_Circ aCircle(theCircle);
408   GeomPointPtr aCenter = thePlane->project(aCircle.center());
409   GeomPnt2dPtr aCenterInSketch = sketch()->to2D(aCenter);
410
411   // update attributes of projection
412   std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
413       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
414       theProjection->attribute(SketchPlugin_Circle::CENTER_ID()));
415   aCenterPnt->setValue(aCenterInSketch);
416   theProjection->real(SketchPlugin_Circle::RADIUS_ID())->setValue(aCircle.radius());
417   return true;
418 }
419
420 bool SketchPlugin_Projection::fillEllipse(FeaturePtr& theProjection,
421                                           const GeomCurvePtr& theEllipse,
422                                           const GeomPlanePtr& thePlane)
423 {
424   rebuildProjectedFeature(theProjection, CIRCLE_ELLIPSE_PROJECTION(), SketchPlugin_Ellipse::ID());
425
426   GeomAPI_Ellipse anEllipse(theEllipse);
427   GeomPointPtr aCenter = thePlane->project(anEllipse.center());
428   GeomPnt2dPtr aCenterInSketch = sketch()->to2D(aCenter);
429   GeomPointPtr aFocus = thePlane->project(anEllipse.firstFocus());
430   GeomPnt2dPtr aFocusInSketch = sketch()->to2D(aFocus);
431
432   // update attributes of projection
433   std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
434       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
435       theProjection->attribute(SketchPlugin_Ellipse::CENTER_ID()));
436   aCenterPnt->setValue(aCenterInSketch);
437   std::shared_ptr<GeomDataAPI_Point2D> aFocusPnt =
438       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
439       theProjection->attribute(SketchPlugin_Ellipse::FIRST_FOCUS_ID()));
440   aFocusPnt->setValue(aFocusInSketch);
441   theProjection->real(SketchPlugin_Ellipse::MINOR_RADIUS_ID())->setValue(anEllipse.minorRadius());
442   return true;
443 }
444
445 bool SketchPlugin_Projection::fillEllipticArc(FeaturePtr& theProjection,
446                                               const GeomCurvePtr& theEllipticArc,
447                                               const GeomPlanePtr& thePlane)
448 {
449   rebuildProjectedFeature(theProjection, ARC_PROJECTION(), SketchPlugin_EllipticArc::ID());
450
451   GeomAPI_Ellipse anEllipse(theEllipticArc);
452
453   double aNormalsDot = anEllipse.normal()->dot(thePlane->direction());
454   if (fabs(fabs(aNormalsDot) - 1.0) > tolerance)
455     return false; // arc is not in the plane, parallel to the sketch plane
456
457   bool isInversed = aNormalsDot < 0.;
458
459   GeomPointPtr aCenter = thePlane->project(anEllipse.center());
460   GeomPnt2dPtr aCenterInSketch = sketch()->to2D(aCenter);
461   GeomPointPtr aFocus = thePlane->project(anEllipse.firstFocus());
462   GeomPnt2dPtr aFocusInSketch = sketch()->to2D(aFocus);
463
464   GeomPointPtr aFirst = theEllipticArc->getPoint(theEllipticArc->startParam());
465   GeomPnt2dPtr aFirstInSketch = sketch()->to2D(thePlane->project(aFirst));
466   GeomPointPtr aLast = theEllipticArc->getPoint(theEllipticArc->endParam());
467   GeomPnt2dPtr aLastInSketch = sketch()->to2D(thePlane->project(aLast));
468
469   bool aWasBlocked = theProjection->data()->blockSendAttributeUpdated(true);
470
471   // update attributes of projection
472   std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
473       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
474       theProjection->attribute(SketchPlugin_EllipticArc::CENTER_ID()));
475   std::shared_ptr<GeomDataAPI_Point2D> aFocusPnt =
476       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
477       theProjection->attribute(SketchPlugin_EllipticArc::FIRST_FOCUS_ID()));
478   std::shared_ptr<GeomDataAPI_Point2D> aStartPnt =
479       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
480       theProjection->attribute(SketchPlugin_EllipticArc::START_POINT_ID()));
481   std::shared_ptr<GeomDataAPI_Point2D> aEndPnt =
482       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
483       theProjection->attribute(SketchPlugin_EllipticArc::END_POINT_ID()));
484   aStartPnt->setValue(aFirstInSketch);
485   aEndPnt->setValue(aLastInSketch);
486   aCenterPnt->setValue(aCenterInSketch);
487   aFocusPnt->setValue(aFocusInSketch);
488   theProjection->boolean(SketchPlugin_EllipticArc::REVERSED_ID())->setValue(isInversed);
489
490   theProjection->data()->blockSendAttributeUpdated(aWasBlocked);
491   return true;
492 }
493
494 bool SketchPlugin_Projection::fillBSpline(FeaturePtr& theProjection,
495                                           const GeomCurvePtr& theCurve,
496                                           const GeomPlanePtr& thePlane)
497 {
498   rebuildProjectedFeature(theProjection, BSPLINE_PROJECTION(), SketchPlugin_BSpline::ID());
499
500   GeomAPI_BSpline aBSpline(theCurve);
501
502   theProjection->integer(SketchPlugin_BSpline::DEGREE_ID())->setValue(aBSpline.degree());
503
504   AttributePoint2DArrayPtr aPolesAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
505       theProjection->attribute(SketchPlugin_BSpline::POLES_ID()));
506   std::list<GeomPointPtr> aPoles = aBSpline.poles();
507   aPolesAttr->setSize((int)aPoles.size());
508   std::list<GeomPointPtr>::iterator anIt = aPoles.begin();
509   for (int anIndex = 0; anIt != aPoles.end(); ++anIt, ++anIndex) {
510     GeomPnt2dPtr aPoleInSketch = sketch()->to2D(*anIt);
511     aPolesAttr->setPnt(anIndex, aPoleInSketch);
512   }
513
514   AttributeDoubleArrayPtr aWeightsAttr =
515       theProjection->data()->realArray(SketchPlugin_BSpline::WEIGHTS_ID());
516   std::list<double> aWeights = aBSpline.weights();
517   if (aWeights.empty()) { // rational B-spline
518     int aSize = (int)aPoles.size();
519     aWeightsAttr->setSize(aSize);
520     for (int anIndex = 0; anIndex < aSize; ++anIndex)
521       aWeightsAttr->setValue(anIndex, 1.0);
522   }
523   else { // non-rational B-spline
524     aWeightsAttr->setSize((int)aWeights.size());
525     std::list<double>::iterator anIt = aWeights.begin();
526     for (int anIndex = 0; anIt != aWeights.end(); ++anIt, ++anIndex)
527       aWeightsAttr->setValue(anIndex, *anIt);
528   }
529
530   AttributeDoubleArrayPtr aKnotsAttr =
531       theProjection->data()->realArray(SketchPlugin_BSpline::KNOTS_ID());
532   std::list<double> aKnots = aBSpline.knots();
533   int aSize = (int)aKnots.size();
534   aKnotsAttr->setSize(aSize);
535   std::list<double>::iterator aKIt = aKnots.begin();
536   for (int index = 0; index < aSize; ++index, ++aKIt)
537     aKnotsAttr->setValue(index, *aKIt);
538
539   AttributeIntArrayPtr aMultsAttr =
540       theProjection->data()->intArray(SketchPlugin_BSpline::MULTS_ID());
541   std::list<int> aMultiplicities = aBSpline.mults();
542   aSize = (int)aMultiplicities.size();
543   aMultsAttr->setSize(aSize);
544   std::list<int>::iterator aMIt = aMultiplicities.begin();
545   for (int index = 0; index < aSize; ++index, ++aMIt)
546     aMultsAttr->setValue(index, *aMIt);
547
548   return true;
549 }