Salome HOME
Support of wide string
[modules/shaper.git] / src / SketchAPI / SketchAPI_BSpline.cpp
1 // Copyright (C) 2019-2020  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 "SketchAPI_BSpline.h"
21
22 #include <GeomAPI_BSpline2d.h>
23 #include <GeomAPI_Pnt2d.h>
24
25 #include <GeomAlgoAPI_EdgeBuilder.h>
26
27 #include <ModelHighAPI_Double.h>
28 #include <ModelHighAPI_Dumper.h>
29 #include <ModelHighAPI_Integer.h>
30 #include <ModelHighAPI_Selection.h>
31 #include <ModelHighAPI_Tools.h>
32
33 #include <ModelAPI_Tools.h>
34
35 #include <SketchPlugin_ConstraintCoincidenceInternal.h>
36 #include <SketchPlugin_Line.h>
37 #include <SketchPlugin_Point.h>
38
39 #include <cmath>
40
41
42 SketchAPI_BSpline::SketchAPI_BSpline(const std::shared_ptr<ModelAPI_Feature> & theFeature)
43   : SketchAPI_SketchEntity(theFeature)
44 {
45   initialize();
46 }
47
48 SketchAPI_BSpline::SketchAPI_BSpline(const std::shared_ptr<ModelAPI_Feature>& theFeature,
49                                      bool theInitialize)
50   : SketchAPI_SketchEntity(theFeature)
51 {
52   if (theInitialize)
53     initialize();
54 }
55
56 SketchAPI_BSpline::~SketchAPI_BSpline()
57 {
58 }
59
60 void SketchAPI_BSpline::setByDegreePolesAndWeights(const ModelHighAPI_Integer& theDegree,
61                                                    const std::list<GeomPnt2dPtr>& thePoles,
62                                                    const std::list<ModelHighAPI_Double>& theWeights)
63 {
64   std::list<ModelHighAPI_Double> aWeights;
65   if (theWeights.size() <= 1) {
66     // prepare array of equal weights
67     aWeights.assign(thePoles.size(),
68         theWeights.empty() ? ModelHighAPI_Double(1.0) : theWeights.front());
69   }
70   else
71     aWeights = theWeights;
72
73   ModelHighAPI_Integer aDegree = theDegree;
74   std::list<ModelHighAPI_Double> aKnots;
75   std::list<ModelHighAPI_Integer> aMults;
76   getDefaultParameters(thePoles, aWeights, aDegree, aKnots, aMults);
77
78   setByParameters(aDegree, thePoles, aWeights, aKnots, aMults);
79 }
80
81 void SketchAPI_BSpline::setByParameters(const ModelHighAPI_Integer& theDegree,
82                                         const std::list<GeomPnt2dPtr>& thePoles,
83                                         const std::list<ModelHighAPI_Double>& theWeights,
84                                         const std::list<ModelHighAPI_Double>& theKnots,
85                                         const std::list<ModelHighAPI_Integer>& theMults)
86 {
87   fillAttribute(theDegree, degree());
88
89   fillAttribute(thePoles, poles());
90   if (theWeights.size() <= 1) {
91     // prepare array of equal weights
92     std::list<ModelHighAPI_Double> aWeights(thePoles.size(),
93         theWeights.empty() ? ModelHighAPI_Double(1.0) : theWeights.front());
94     fillAttribute(aWeights, weights());
95   }
96   else
97     fillAttribute(theWeights, weights());
98
99   fillAttribute(theKnots, knots());
100   fillAttribute(theMults, multiplicities());
101
102   if (feature()->getKind() != SketchPlugin_BSplinePeriodic::ID())
103     setStartAndEndPoints();
104   execute();
105 }
106
107 void SketchAPI_BSpline::setStartAndEndPoints()
108 {
109   fillAttribute(poles()->pnt(0), startPoint());
110   fillAttribute(poles()->pnt(poles()->size() - 1), endPoint());
111 }
112
113 void SketchAPI_BSpline::setByExternal(const ModelHighAPI_Selection & theExternal)
114 {
115   fillAttribute(theExternal, external());
116   execute();
117 }
118
119 static CompositeFeaturePtr sketchForFeature(FeaturePtr theFeature)
120 {
121   const std::set<AttributePtr>& aRefs = theFeature->data()->refsToMe();
122   for (std::set<AttributePtr>::const_iterator anIt = aRefs.begin(); anIt != aRefs.end(); ++anIt)
123     if ((*anIt)->id() == SketchPlugin_Sketch::FEATURES_ID())
124       return std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
125   return CompositeFeaturePtr();
126 }
127
128 static void createInternalConstraint(const CompositeFeaturePtr& theSketch,
129                                      const AttributePoint2DPtr& thePoint,
130                                      const AttributePoint2DArrayPtr& thePoles,
131                                      const int thePoleIndex)
132 {
133   FeaturePtr aConstraint = theSketch->addFeature(SketchPlugin_ConstraintCoincidenceInternal::ID());
134   aConstraint->refattr(SketchPlugin_Constraint::ENTITY_A())->setAttr(thePoint);
135   aConstraint->refattr(SketchPlugin_Constraint::ENTITY_B())->setAttr(thePoles);
136   aConstraint->integer(SketchPlugin_ConstraintCoincidenceInternal::INDEX_ENTITY_B())
137       ->setValue(thePoleIndex);
138   aConstraint->execute();
139 }
140
141 static void createPole(const CompositeFeaturePtr& theSketch,
142                        const FeaturePtr& theBSpline,
143                        const AttributePoint2DArrayPtr& thePoles,
144                        const int thePoleIndex,
145                        const bool theAuxiliary,
146                        std::list<FeaturePtr>& theEntities)
147 {
148   GeomPnt2dPtr aPole = thePoles->pnt(thePoleIndex);
149
150   FeaturePtr aPointFeature = theSketch->addFeature(SketchPlugin_Point::ID());
151   AttributePoint2DPtr aCoord = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
152       aPointFeature->attribute(SketchPlugin_Point::COORD_ID()));
153   aCoord->setValue(aPole);
154   aPointFeature->reference(SketchPlugin_Point::PARENT_ID())->setValue(theBSpline);
155   aPointFeature->execute();
156
157   std::wostringstream aName;
158   aName << theBSpline->name() << "_" << ModelAPI_Tools::toWString(thePoles->id()) << "_" << thePoleIndex;
159   aPointFeature->data()->setName(aName.str());
160   aPointFeature->lastResult()->data()->setName(aName.str());
161
162   aPointFeature->boolean(SketchPlugin_Point::AUXILIARY_ID())->setValue(theAuxiliary);
163
164   createInternalConstraint(theSketch, aCoord, thePoles, thePoleIndex);
165
166   theEntities.push_back(aPointFeature);
167 }
168
169 static void createSegment(const CompositeFeaturePtr& theSketch,
170                           const FeaturePtr& theBSpline,
171                           const AttributePoint2DArrayPtr& thePoles,
172                           const int theStartPoleIndex,
173                           const bool theAuxiliary,
174                           std::list<FeaturePtr>& theEntities)
175 {
176   int aEndPoleIndex = (theStartPoleIndex + 1) % thePoles->size();
177   GeomPnt2dPtr aStartPoint = thePoles->pnt(theStartPoleIndex);
178   GeomPnt2dPtr aEndPoint = thePoles->pnt(aEndPoleIndex);
179
180   FeaturePtr aLineFeature = theSketch->addFeature(SketchPlugin_Line::ID());
181   AttributePoint2DPtr aLineStart = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
182       aLineFeature->attribute(SketchPlugin_Line::START_ID()));
183   aLineStart->setValue(aStartPoint);
184   AttributePoint2DPtr aLineEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
185       aLineFeature->attribute(SketchPlugin_Line::END_ID()));
186   aLineEnd->setValue(aEndPoint);
187   aLineFeature->reference(SketchPlugin_Point::PARENT_ID())->setValue(theBSpline);
188   aLineFeature->execute();
189
190   std::wostringstream aName;
191   aName << theBSpline->name() << "_segment_" << theStartPoleIndex << "_" << aEndPoleIndex;
192   aLineFeature->data()->setName(aName.str());
193   aLineFeature->lastResult()->data()->setName(aName.str());
194
195   aLineFeature->boolean(SketchPlugin_Line::AUXILIARY_ID())->setValue(theAuxiliary);
196
197   createInternalConstraint(theSketch, aLineStart, thePoles, theStartPoleIndex);
198   createInternalConstraint(theSketch, aLineEnd, thePoles, aEndPoleIndex);
199
200   theEntities.push_back(aLineFeature);
201 }
202
203 static void toMapOfAuxIndices(const std::list<int>& theRegular,
204                               const std::list<int>& theAuxiliary,
205                               std::map<int, bool>& theIndices)
206 {
207   for (auto it = theRegular.begin(); it != theRegular.end(); ++it)
208     theIndices[*it] = false;
209   for (auto it = theAuxiliary.begin(); it != theAuxiliary.end(); ++it)
210     theIndices[*it] = true;
211 }
212
213 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_BSpline::controlPoles(
214     const std::list<int>& regular,
215     const std::list<int>& auxiliary) const
216 {
217   std::map<int, bool> anAux;
218   toMapOfAuxIndices(regular, auxiliary, anAux);
219
220   std::list<FeaturePtr> anEntities;
221
222   FeaturePtr aBSpline = feature();
223   CompositeFeaturePtr aSketch = sketchForFeature(aBSpline);
224   AttributePoint2DArrayPtr aPoles = poles();
225
226   for (auto it = anAux.begin(); it != anAux.end(); ++it)
227     createPole(aSketch, aBSpline, aPoles, it->first, it->second, anEntities);
228
229   return SketchAPI_SketchEntity::wrap(anEntities);
230 }
231
232 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_BSpline::controlPolygon(
233     const std::list<int>& regular,
234     const std::list<int>& auxiliary) const
235 {
236   std::map<int, bool> anAux;
237   toMapOfAuxIndices(regular, auxiliary, anAux);
238
239   std::list<FeaturePtr> anEntities;
240
241   FeaturePtr aBSpline = feature();
242   CompositeFeaturePtr aSketch = sketchForFeature(aBSpline);
243   AttributePoint2DArrayPtr aPoles = poles();
244
245   for (auto it = anAux.begin(); it != anAux.end(); ++it)
246     createSegment(aSketch, aBSpline, aPoles, it->first, it->second, anEntities);
247
248   return SketchAPI_SketchEntity::wrap(anEntities);
249 }
250
251
252 void SketchAPI_BSpline::getDefaultParameters(
253     const std::list<std::shared_ptr<GeomAPI_Pnt2d> >& thePoles,
254     const std::list<ModelHighAPI_Double>& theWeights,
255     ModelHighAPI_Integer& theDegree,
256     std::list<ModelHighAPI_Double>& theKnots,
257     std::list<ModelHighAPI_Integer>& theMults) const
258 {
259   std::shared_ptr<GeomAPI_BSpline2d> aBSplineCurve;
260   try {
261     std::list<double> aWeights;
262     for (std::list<ModelHighAPI_Double>::const_iterator it = theWeights.begin();
263          it != theWeights.end(); ++it)
264       aWeights.push_back(it->value());
265
266     bool isPeriodic = feature()->getKind() == SketchPlugin_BSplinePeriodic::ID();
267     if (theDegree.intValue() < 0)
268       aBSplineCurve.reset(new GeomAPI_BSpline2d(thePoles, aWeights, isPeriodic));
269     else {
270       aBSplineCurve.reset(new GeomAPI_BSpline2d(theDegree.intValue(), thePoles, aWeights,
271                                                 std::list<double>(), std::list<int>(), isPeriodic));
272     }
273   }
274   catch (...) {
275     // cannot build a B-spline curve
276     return;
277   }
278
279   theDegree = aBSplineCurve->degree();
280   std::list<double> aKnots = aBSplineCurve->knots();
281   std::list<int> aMults = aBSplineCurve->mults();
282   theKnots.assign(aKnots.begin(), aKnots.end());
283   theMults.assign(aMults.begin(), aMults.end());
284 }
285
286 void SketchAPI_BSpline::checkDefaultParameters(bool& isDefaultDegree,
287                                                bool& isDefaultWeights,
288                                                bool& isDefaultKnotsMults) const
289 {
290   static const double TOLERANCE = 1.e-7;
291
292   AttributePoint2DArrayPtr aPolesAttr = poles();
293   AttributeDoubleArrayPtr aWeightsAttr = weights();
294   AttributeDoubleArrayPtr aKnotsAttr = knots();
295   AttributeIntArrayPtr aMultsAttr = multiplicities();
296
297   std::list<GeomPnt2dPtr> aPoles;
298   std::list<ModelHighAPI_Double> aWeights;
299   isDefaultWeights = true;
300   for (int anIndex = 0; anIndex < aPolesAttr->size(); ++anIndex) {
301     aPoles.push_back(aPolesAttr->pnt(anIndex));
302     double aCurWeight = aWeightsAttr->value(anIndex);
303     isDefaultWeights = isDefaultWeights && fabs(aCurWeight - 1.0) < TOLERANCE;
304     aWeights.push_back(aCurWeight);
305   }
306
307   ModelHighAPI_Integer aDegree(-1);
308   std::list<ModelHighAPI_Double> aKnots;
309   std::list<ModelHighAPI_Integer> aMults;
310   getDefaultParameters(aPoles, aWeights, aDegree, aKnots, aMults);
311   isDefaultDegree = aDegree.intValue() == degree()->value();
312   if (!isDefaultDegree) {
313     // recalculate knots and multiplicities with the actual degree
314     aDegree = degree()->value();
315     getDefaultParameters(aPoles, aWeights, aDegree, aKnots, aMults);
316   }
317
318   isDefaultKnotsMults = aKnotsAttr->size() == (int)aKnots.size()
319                      && aMultsAttr->size() == (int)aMults.size();
320   if (isDefaultKnotsMults) {
321     std::list<ModelHighAPI_Double>::iterator anIt = aKnots.begin();
322     for (int anIndex = 0; isDefaultKnotsMults && anIt != aKnots.end(); ++anIt, ++anIndex)
323       isDefaultKnotsMults = fabs(anIt->value() - aKnotsAttr->value(anIndex)) < TOLERANCE;
324   }
325   if (isDefaultKnotsMults) {
326     std::list<ModelHighAPI_Integer>::iterator anIt = aMults.begin();
327     for (int anIndex = 0; isDefaultKnotsMults && anIt != aMults.end(); ++anIt, ++anIndex)
328       isDefaultKnotsMults = anIt->intValue() == aMultsAttr->value(anIndex);
329   }
330
331   isDefaultDegree = isDefaultDegree && isDefaultKnotsMults;
332   isDefaultWeights = isDefaultWeights && isDefaultKnotsMults;
333 }
334
335
336 static void bsplineAuxiliaryFeature(const AttributeRefAttrPtr& theReference,
337                                     FeaturePtr& thePoint,
338                                     FeaturePtr& theSegment)
339 {
340   ObjectPtr anAuxObject;
341   if (theReference->isObject())
342     anAuxObject = theReference->object();
343   else
344     anAuxObject = theReference->attr()->owner();
345
346   FeaturePtr anAuxFeature = ModelAPI_Feature::feature(anAuxObject);
347   if (anAuxFeature->getKind() == SketchPlugin_Point::ID())
348     thePoint = anAuxFeature;
349   else if (anAuxFeature->getKind() == SketchPlugin_Line::ID() &&
350            theReference->attr()->id() == SketchPlugin_Line::START_ID()) {
351     // process only coincidence with start point
352     theSegment = anAuxFeature;
353   }
354 }
355
356 static void collectAuxiliaryFeatures(FeaturePtr theBSpline,
357                                      std::map<int, FeaturePtr>& thePoints,
358                                      std::map<int, FeaturePtr>& theSegments)
359 {
360   const std::set<AttributePtr>& aRefs = theBSpline->data()->refsToMe();
361   for (std::set<AttributePtr>::const_iterator aRefIt = aRefs.begin();
362        aRefIt != aRefs.end(); ++aRefIt) {
363     FeaturePtr anOwner = ModelAPI_Feature::feature((*aRefIt)->owner());
364     if (anOwner->getKind() == SketchPlugin_ConstraintCoincidenceInternal::ID()) {
365       // process internal constraints only
366       AttributeRefAttrPtr aRefAttrA = anOwner->refattr(SketchPlugin_Constraint::ENTITY_A());
367       AttributeRefAttrPtr aRefAttrB = anOwner->refattr(SketchPlugin_Constraint::ENTITY_B());
368       AttributePtr anAttrA = aRefAttrA->attr();
369       AttributePtr anAttrB = aRefAttrB->attr();
370
371       AttributeIntegerPtr aPoleIndex;
372       FeaturePtr aPoint, aLine;
373       if (anAttrA && anAttrA->attributeType() == GeomDataAPI_Point2DArray::typeId()) {
374         aPoleIndex = anOwner->integer(SketchPlugin_ConstraintCoincidenceInternal::INDEX_ENTITY_A());
375         bsplineAuxiliaryFeature(aRefAttrB, aPoint, aLine);
376       }
377       else if (anAttrB && anAttrB->attributeType() == GeomDataAPI_Point2DArray::typeId()) {
378         aPoleIndex = anOwner->integer(SketchPlugin_ConstraintCoincidenceInternal::INDEX_ENTITY_B());
379         bsplineAuxiliaryFeature(aRefAttrA, aPoint, aLine);
380       }
381
382       if (aPoint)
383         thePoints[aPoleIndex->value()] = aPoint;
384       else if (aLine)
385         theSegments[aPoleIndex->value()] = aLine;
386     }
387   }
388 }
389
390 void SketchAPI_BSpline::dump(ModelHighAPI_Dumper& theDumper) const
391 {
392   if (isCopy())
393     return; // no need to dump copied feature
394
395   FeaturePtr aBase = feature();
396   const std::string& aSketchName = theDumper.parentName(aBase);
397
398   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
399   if (anExternal->context()) {
400     // B-spline is external
401     theDumper << aBase << " = " << aSketchName << ".addSpline(" << anExternal << ")" << std::endl;
402   } else {
403     // check if some B-spline parameters are default and should not be dumped
404     bool isDefaultDegree, isDefaultWeights, isDefaultKnotsMults;
405     checkDefaultParameters(isDefaultDegree, isDefaultWeights, isDefaultKnotsMults);
406
407     theDumper << aBase << " = " << aSketchName << ".addSpline(";
408     if (!isDefaultDegree)
409       theDumper << "degree = " << degree() << ", ";
410     theDumper << "poles = " << poles();
411     if (!isDefaultWeights)
412       theDumper << ", weights = " << weights();
413     if (!isDefaultKnotsMults)
414       theDumper << ", knots = " << knots() << ", multiplicities = " << multiplicities();
415     if (aBase->getKind() == SketchPlugin_BSplinePeriodic::ID())
416       theDumper << ", periodic = True";
417     theDumper << ")" << std::endl;
418   }
419   // dump "auxiliary" flag if necessary
420   SketchAPI_SketchEntity::dump(theDumper);
421
422   // dump control polygon
423   std::map<int, FeaturePtr> anAuxPoles, anAuxSegments;
424   collectAuxiliaryFeatures(aBase, anAuxPoles, anAuxSegments);
425
426   if (!anAuxPoles.empty())
427     dumpControlPolygon(theDumper, aBase, "controlPoles", anAuxPoles);
428   if (!anAuxSegments.empty())
429     dumpControlPolygon(theDumper, aBase, "controlPolygon", anAuxSegments);
430 }
431
432 static void dumpList(ModelHighAPI_Dumper& theDumper,
433                      const std::string& theAttrName,
434                      const std::set<int>& theIndices)
435 {
436   theDumper << theAttrName << " = [";
437   std::set<int>::const_iterator it = theIndices.begin();
438   theDumper << *it;
439   for (++it; it != theIndices.end(); ++it)
440     theDumper << ", " << *it;
441   theDumper << "]";
442 }
443
444 void SketchAPI_BSpline::dumpControlPolygon(
445     ModelHighAPI_Dumper& theDumper,
446     const FeaturePtr& theBSpline,
447     const std::string& theMethod,
448     const std::map<int, FeaturePtr>& theAuxFeatures) const
449 {
450   theDumper << "[";
451   bool isFirst = true;
452   // dump features and split them to auxiliary and regular
453   std::set<int> aRegular, anAuxiliary;
454   for (std::map<int, FeaturePtr>::const_iterator it = theAuxFeatures.begin();
455        it != theAuxFeatures.end(); ++it) {
456     if (!isFirst)
457       theDumper << ", ";
458     theDumper << theDumper.name(it->second, false);
459     theDumper.doNotDumpFeature(it->second);
460     isFirst = false;
461
462     if (it->second->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value())
463       anAuxiliary.insert(it->first);
464     else
465       aRegular.insert(it->first);
466   }
467   theDumper << "] = " << theDumper.name(theBSpline) << "." << theMethod << "(";
468   if (!aRegular.empty()) {
469     dumpList(theDumper, "regular", aRegular);
470     if (!anAuxiliary.empty())
471       theDumper << ", ";
472   }
473   if (!anAuxiliary.empty())
474     dumpList(theDumper, "auxiliary", anAuxiliary);
475   theDumper << ")" << std::endl;
476 }
477
478 static void setCoordinates(const FeaturePtr& theFeature,
479                            const std::string& theAttrName,
480                            const GeomPnt2dPtr& theCoordinates)
481 {
482   AttributePoint2DPtr aPoint =
483       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->attribute(theAttrName));
484   aPoint->setValue(theCoordinates);
485 }
486
487 bool SketchAPI_BSpline::insertPole(const int theIndex,
488                                    const GeomPnt2dPtr& theCoordinates,
489                                    const ModelHighAPI_Double& theWeight)
490 {
491   std::ostringstream anActionName;
492   anActionName << SketchPlugin_BSplineBase::ADD_POLE_ACTION_ID() << "#" << theIndex;
493   bool isOk = feature()->customAction(anActionName.str());
494   if (isOk) {
495     int anIndex = theIndex + 1;
496     if (feature()->getKind() == SketchPlugin_BSpline::ID() && anIndex + 1 >= poles()->size())
497       anIndex = poles()->size() - 2;
498     // initialize coordinates and weight of new pole
499     poles()->setPnt(anIndex, theCoordinates);
500     weights()->setValue(anIndex, theWeight.value());
501
502     // update coordinates of points of control polygon
503     std::map<int, FeaturePtr> aPoints, aLines;
504     collectAuxiliaryFeatures(feature(), aPoints, aLines);
505     std::map<int, FeaturePtr>::iterator aFound = aPoints.find(anIndex);
506     if (aFound != aPoints.end())
507       setCoordinates(aFound->second, SketchPlugin_Point::COORD_ID(), theCoordinates);
508     aFound = aLines.find(anIndex);
509     if (aFound != aLines.end())
510       setCoordinates(aFound->second, SketchPlugin_Line::START_ID(), theCoordinates);
511     aFound = aLines.find(anIndex - 1);
512     if (aFound != aLines.end())
513       setCoordinates(aFound->second, SketchPlugin_Line::END_ID(), theCoordinates);
514   }
515   return isOk;
516 }
517
518
519
520 // =================================================================================================
521 SketchAPI_BSplinePeriodic::SketchAPI_BSplinePeriodic(const FeaturePtr& theFeature)
522   : SketchAPI_BSpline(theFeature, false)
523 {
524   initialize();
525 }