1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : GEOMGUI_DimensionProperty.cxx
24 // Author : Anton POLETAEV, Open CASCADE S.A.S.
27 #include "GEOMGUI_DimensionProperty.h"
30 #include <Standard_ProgramError.hxx>
31 #include <gp_Trsf.hxx>
33 #include <SalomeApp_Study.h>
35 // Static patterns for casting value-to-string & value-from-string. The patterns are:
36 // ITEM: { name[string] : visibility : type : values[composite] };
37 // PLANE: a[float] : b[float] : c[float] : d[float]
38 // PROPS: flyout[float] : text h pos[int] : text v pos[int] : arrow pos[int]
39 // XYZ: x [float] : y[float] : z[float]
40 // FLOAT: value [float]
43 static const QString PATTERN_ITEM_GROUP = "\\{ (Name=(?::{2,}|.)*:(?!:)Visible=.*:Type=.*:.*) \\}";
44 static const QString PATTERN_ITEM = "Name=((?::{2,}|.)*):(?!:)Visible=(\\d{1}):Type=(\\d{1}):(.*)";
45 static const QString PATTERN_PLANE = "Plane=\\{(.*):(.*):(.*):(.*)\\}";
46 static const QString PATTERN_PROPS = "Flyout=(.*):TextH=(.*):TextV=(.*):Arrow=(.*)";
47 static const QString PATTERN_XYZ = "%1=\\{(.*):(.*):(.*)\\}";
48 static const QString PATTERN_FLOAT = "%1=(.*)";
50 static const QString PATTERN_LENGTH =
53 PATTERN_XYZ.arg( "Point1" ) + ":" +
54 PATTERN_XYZ.arg( "Point2" );
56 static const QString PATTERN_DIAMETER =
59 PATTERN_XYZ.arg( "Position" ) + ":" +
60 PATTERN_XYZ.arg( "NDir" ) + ":" +
61 PATTERN_XYZ.arg( "XDir" ) + ":" +
62 PATTERN_FLOAT.arg( "Radius" );
64 static const QString PATTERN_ANGLE =
66 PATTERN_XYZ.arg( "Point1" ) + ":" +
67 PATTERN_XYZ.arg( "Point2" ) + ":" +
68 PATTERN_XYZ.arg( "Point3" );
71 //=================================================================================
72 // function : Length::Init
74 //=================================================================================
75 void GEOMGUI_DimensionProperty::Length::Init( const Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS )
78 aFromLCS.SetTransformation( gp_Ax3(), theLCS );
80 FirstPoint = theIO->FirstPoint().Transformed( aFromLCS );
81 SecondPoint = theIO->SecondPoint().Transformed( aFromLCS );
82 Plane = theIO->GetPlane().Transformed( aFromLCS );
83 Flyout = theIO->GetFlyout();
84 TextHPos = theIO->DimensionAspect()->TextHorizontalPosition();
85 TextVPos = theIO->DimensionAspect()->TextVerticalPosition();
86 ArrowPos = theIO->DimensionAspect()->ArrowOrientation();
89 //=================================================================================
90 // function : Length::Update
92 //=================================================================================
93 void GEOMGUI_DimensionProperty::Length::Update( Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS )
96 aToLCS.SetTransformation( theLCS, gp_Ax3() );
98 gp_Pnt aPoint1 = FirstPoint.Transformed( aToLCS );
99 gp_Pnt aPoint2 = SecondPoint.Transformed( aToLCS );
100 gp_Pln aPlane = Plane.Transformed( aToLCS );
102 theIO->SetMeasuredGeometry( aPoint1, aPoint2, aPlane );
103 theIO->SetFlyout( Flyout );
105 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
106 aStyle->SetTextHorizontalPosition( TextHPos );
107 aStyle->SetTextVerticalPosition( TextVPos );
108 aStyle->SetArrowOrientation( ArrowPos );
109 theIO->SetDimensionAspect( aStyle );
112 //=================================================================================
113 // function : Length::ToValues
115 //=================================================================================
116 void GEOMGUI_DimensionProperty::Length::ToValues(std::vector<double>& theValues) const
118 // custom plane [2,3,4,5]
119 Standard_Real A, B, C, D;
120 Plane.Coefficients( A, B, C, D );
121 theValues.push_back( (double) A );
122 theValues.push_back( (double) B );
123 theValues.push_back( (double) C );
124 theValues.push_back( (double) D );
127 theValues.push_back( (double) Flyout );
130 theValues.push_back( (double) TextHPos );
131 theValues.push_back( (double) TextVPos );
134 theValues.push_back( (double) ArrowPos );
136 // point 1 [10,11,12]
137 theValues.push_back( (double) FirstPoint.X() );
138 theValues.push_back( (double) FirstPoint.Y() );
139 theValues.push_back( (double) FirstPoint.Z() );
141 // point 2 [13,14,15]
142 theValues.push_back( (double) SecondPoint.X() );
143 theValues.push_back( (double) SecondPoint.Y() );
144 theValues.push_back( (double) SecondPoint.Z() );
147 //=================================================================================
148 // function : Length::FromValues
150 //=================================================================================
151 void GEOMGUI_DimensionProperty::Length::FromValues(int& theIt, const std::vector<double>& theValues)
153 // custom plane [2,3,4,5]
154 Standard_Real A = (Standard_Real) theValues[theIt++];
155 Standard_Real B = (Standard_Real) theValues[theIt++];
156 Standard_Real C = (Standard_Real) theValues[theIt++];
157 Standard_Real D = (Standard_Real) theValues[theIt++];
158 Plane = gp_Pln( A, B, C, D );
161 Flyout = (Standard_Real) theValues[theIt++];
164 TextHPos = (Prs3d_DimensionTextHorizontalPosition)(int)theValues[theIt++];
165 TextVPos = (Prs3d_DimensionTextVerticalPosition) (int)theValues[theIt++];
168 ArrowPos = (Prs3d_DimensionArrowOrientation) (int)theValues[theIt++];
170 // point 1 [10,11,12]
171 Standard_Real aFirstX = theValues[theIt++];
172 Standard_Real aFirstY = theValues[theIt++];
173 Standard_Real aFirstZ = theValues[theIt++];
174 FirstPoint = gp_Pnt( aFirstX, aFirstY, aFirstZ );
176 // point 2 [13,14,15]
177 Standard_Real aSecondX = theValues[theIt++];
178 Standard_Real aSecondY = theValues[theIt++];
179 Standard_Real aSecondZ = theValues[theIt++];
180 SecondPoint = gp_Pnt( aSecondX, aSecondY, aSecondZ );
183 //=================================================================================
184 // function : Length::operator ==
186 //=================================================================================
187 bool GEOMGUI_DimensionProperty::Length::operator == (const Length& theOther) const
189 if ( FirstPoint.X() != theOther.FirstPoint.X()
190 || FirstPoint.Y() != theOther.FirstPoint.Y()
191 || FirstPoint.Z() != theOther.FirstPoint.Z()
192 || SecondPoint.X() != theOther.SecondPoint.X()
193 || SecondPoint.Y() != theOther.SecondPoint.Y()
194 || SecondPoint.Z() != theOther.SecondPoint.Z() )
199 if ( Plane.Location().X() != theOther.Plane.Location().X()
200 || Plane.Location().Y() != theOther.Plane.Location().Y()
201 || Plane.Location().Z() != theOther.Plane.Location().Z()
202 || Plane.Axis().Direction().X() != theOther.Plane.Axis().Direction().X()
203 || Plane.Axis().Direction().Y() != theOther.Plane.Axis().Direction().Y()
204 || Plane.Axis().Direction().Z() != theOther.Plane.Axis().Direction().Z() )
209 if ( Flyout != theOther.Flyout
210 || TextHPos != theOther.TextHPos
211 || TextVPos != theOther.TextVPos
212 || ArrowPos != theOther.ArrowPos )
220 //=================================================================================
221 // function : Diameter::Init
223 //=================================================================================
224 void GEOMGUI_DimensionProperty::Diameter::Init( const Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS )
227 aFromLCS.SetTransformation( gp_Ax3(), theLCS );
229 Circle = theIO->Circle().Transformed( aFromLCS );
230 Plane = theIO->GetPlane().Transformed( aFromLCS );
231 Flyout = theIO->GetFlyout();
232 TextHPos = theIO->DimensionAspect()->TextHorizontalPosition();
233 TextVPos = theIO->DimensionAspect()->TextVerticalPosition();
234 ArrowPos = theIO->DimensionAspect()->ArrowOrientation();
237 //=================================================================================
238 // function : Diameter::Update
240 //=================================================================================
241 void GEOMGUI_DimensionProperty::Diameter::Update( Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS )
244 aToLCS.SetTransformation( theLCS, gp_Ax3() );
246 gp_Circ aCircle = Circle.Transformed( aToLCS );
247 gp_Pln aPlane = Plane.Transformed( aToLCS );
249 Standard_Boolean isParallel =
250 aCircle.Axis().Direction().IsParallel( aPlane.Axis().Direction(), Precision::Angular() );
254 theIO->UnsetCustomPlane();
255 theIO->SetMeasuredGeometry( aCircle );
259 theIO->SetCustomPlane( aPlane );
260 theIO->SetMeasuredGeometry( aCircle );
263 theIO->SetFlyout( Flyout );
265 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
266 aStyle->SetTextHorizontalPosition( TextHPos );
267 aStyle->SetTextVerticalPosition( TextVPos );
268 aStyle->SetArrowOrientation( ArrowPos );
269 theIO->SetDimensionAspect( aStyle );
272 //=================================================================================
273 // function : Diameter::ToValues
275 //=================================================================================
276 void GEOMGUI_DimensionProperty::Diameter::ToValues(std::vector<double>& theValues) const
278 // custom plane [2,3,4,5]
279 Standard_Real A, B, C, D;
280 Plane.Coefficients( A, B, C, D );
281 theValues.push_back( (double) A );
282 theValues.push_back( (double) B );
283 theValues.push_back( (double) C );
284 theValues.push_back( (double) D );
287 theValues.push_back( (double) Flyout );
290 theValues.push_back( (double) TextHPos );
291 theValues.push_back( (double) TextVPos );
294 theValues.push_back( (double) ArrowPos );
296 // circle location [10,11,12]
297 theValues.push_back( (double) Circle.Location().X() );
298 theValues.push_back( (double) Circle.Location().Y() );
299 theValues.push_back( (double) Circle.Location().Z() );
301 // circle normal [13,14,15]
302 theValues.push_back( (double) Circle.Axis().Direction().X() );
303 theValues.push_back( (double) Circle.Axis().Direction().Y() );
304 theValues.push_back( (double) Circle.Axis().Direction().Z() );
306 // x-direction [16,17,18]
307 theValues.push_back( (double) Circle.XAxis().Direction().X() );
308 theValues.push_back( (double) Circle.XAxis().Direction().Y() );
309 theValues.push_back( (double) Circle.XAxis().Direction().Z() );
312 theValues.push_back( (double) Circle.Radius() );
315 //=================================================================================
316 // function : Diameter::FromValues
318 //=================================================================================
319 void GEOMGUI_DimensionProperty::Diameter::FromValues(int& theIt, const std::vector<double>& theValues)
321 // custom plane [2,3,4,5]
322 Standard_Real A = (Standard_Real) theValues[theIt++];
323 Standard_Real B = (Standard_Real) theValues[theIt++];
324 Standard_Real C = (Standard_Real) theValues[theIt++];
325 Standard_Real D = (Standard_Real) theValues[theIt++];
326 Plane = gp_Pln( A, B, C, D );
329 Flyout = (Standard_Real) theValues[theIt++];
332 TextHPos = (Prs3d_DimensionTextHorizontalPosition)(int)theValues[theIt++];
333 TextVPos = (Prs3d_DimensionTextVerticalPosition) (int)theValues[theIt++];
336 ArrowPos = (Prs3d_DimensionArrowOrientation) (int)theValues[theIt++];
338 // circle location [10,11,12]
339 Standard_Real aLocX = (Standard_Real) theValues[theIt++];
340 Standard_Real aLocY = (Standard_Real) theValues[theIt++];
341 Standard_Real aLocZ = (Standard_Real) theValues[theIt++];
343 // circle normal [13,14,15]
344 Standard_Real aNormX = (Standard_Real) theValues[theIt++];
345 Standard_Real aNormY = (Standard_Real) theValues[theIt++];
346 Standard_Real aNormZ = (Standard_Real) theValues[theIt++];
348 // x-direction [16,17,18]
349 Standard_Real aXDirX = (Standard_Real) theValues[theIt++];
350 Standard_Real aXDirY = (Standard_Real) theValues[theIt++];
351 Standard_Real aXDirZ = (Standard_Real) theValues[theIt++];
354 Standard_Real aRadius = (Standard_Real) theValues[theIt++];
356 gp_Ax2 anAx( gp_Pnt( aLocX, aLocY, aLocZ ),
357 gp_Dir( aNormX, aNormY, aNormZ ),
358 gp_Dir( aXDirX, aXDirY, aXDirZ ) );
360 Circle = gp_Circ( anAx, aRadius );
363 //=================================================================================
364 // function : Diameter::operator ==
366 //=================================================================================
367 bool GEOMGUI_DimensionProperty::Diameter::operator == (const Diameter& theOther) const
369 if ( Circle.Location().X() != theOther.Circle.Location().X()
370 || Circle.Location().Y() != theOther.Circle.Location().Y()
371 || Circle.Location().Z() != theOther.Circle.Location().Z()
372 || Circle.Axis().Direction().X() != theOther.Circle.Axis().Direction().X()
373 || Circle.Axis().Direction().Y() != theOther.Circle.Axis().Direction().Y()
374 || Circle.Axis().Direction().Z() != theOther.Circle.Axis().Direction().Z()
375 || Circle.XAxis().Direction().X() != theOther.Circle.XAxis().Direction().X()
376 || Circle.XAxis().Direction().Y() != theOther.Circle.XAxis().Direction().Y()
377 || Circle.XAxis().Direction().Z() != theOther.Circle.XAxis().Direction().Z()
378 || Circle.Radius() != theOther.Circle.Radius() )
383 if ( Plane.Location().X() != theOther.Plane.Location().X()
384 || Plane.Location().Y() != theOther.Plane.Location().Y()
385 || Plane.Location().Z() != theOther.Plane.Location().Z()
386 || Plane.Axis().Direction().X() != theOther.Plane.Axis().Direction().X()
387 || Plane.Axis().Direction().Y() != theOther.Plane.Axis().Direction().Y()
388 || Plane.Axis().Direction().Z() != theOther.Plane.Axis().Direction().Z() )
393 if ( Flyout != theOther.Flyout
394 || TextHPos != theOther.TextHPos
395 || TextVPos != theOther.TextVPos
396 || ArrowPos != theOther.ArrowPos )
404 //=================================================================================
405 // function : Angle::Init
407 //=================================================================================
408 void GEOMGUI_DimensionProperty::Angle::Init( const Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS )
411 aFromLCS.SetTransformation( gp_Ax3(), theLCS );
413 FirstPoint = theIO->FirstPoint().Transformed( aFromLCS );
414 SecondPoint = theIO->SecondPoint().Transformed( aFromLCS );
415 CenterPoint = theIO->CenterPoint().Transformed( aFromLCS );
416 Flyout = theIO->GetFlyout();
417 TextHPos = theIO->DimensionAspect()->TextHorizontalPosition();
418 TextVPos = theIO->DimensionAspect()->TextVerticalPosition();
419 ArrowPos = theIO->DimensionAspect()->ArrowOrientation();
422 //=================================================================================
423 // function : Angle::Update
425 //=================================================================================
426 void GEOMGUI_DimensionProperty::Angle::Update( Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS )
429 aToLCS.SetTransformation( theLCS, gp_Ax3() );
431 gp_Pnt aPoint1 = FirstPoint.Transformed( aToLCS );
432 gp_Pnt aPoint2 = CenterPoint.Transformed( aToLCS );
433 gp_Pnt aPoint3 = SecondPoint.Transformed( aToLCS );
435 theIO->SetMeasuredGeometry( aPoint1, aPoint2, aPoint3 );
436 theIO->SetFlyout( Flyout );
438 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
439 aStyle->SetTextHorizontalPosition( TextHPos );
440 aStyle->SetTextVerticalPosition( TextVPos );
441 aStyle->SetArrowOrientation( ArrowPos );
442 theIO->SetDimensionAspect( aStyle );
445 //=================================================================================
446 // function : Angle::ToValues
448 //=================================================================================
449 void GEOMGUI_DimensionProperty::Angle::ToValues(std::vector<double>& theValues) const
452 theValues.push_back( (double) Flyout );
455 theValues.push_back( (double) TextHPos );
456 theValues.push_back( (double) TextVPos );
459 theValues.push_back( (double) ArrowPos );
462 theValues.push_back( (double) FirstPoint.X() );
463 theValues.push_back( (double) FirstPoint.Y() );
464 theValues.push_back( (double) FirstPoint.Z() );
467 theValues.push_back( (double) SecondPoint.X() );
468 theValues.push_back( (double) SecondPoint.Y() );
469 theValues.push_back( (double) SecondPoint.Z() );
472 theValues.push_back( (double) CenterPoint.X() );
473 theValues.push_back( (double) CenterPoint.Y() );
474 theValues.push_back( (double) CenterPoint.Z() );
477 //=================================================================================
478 // function : Angle::FromValues
480 //=================================================================================
481 void GEOMGUI_DimensionProperty::Angle::FromValues(int& theIt, const std::vector<double>& theValues)
484 Flyout = (Standard_Real) theValues[theIt++];
487 TextHPos = (Prs3d_DimensionTextHorizontalPosition)(int)theValues[theIt++];
488 TextVPos = (Prs3d_DimensionTextVerticalPosition) (int)theValues[theIt++];
491 ArrowPos = (Prs3d_DimensionArrowOrientation) (int)theValues[theIt++];
494 Standard_Real aFirstX = (Standard_Real) theValues[theIt++];
495 Standard_Real aFirstY = (Standard_Real) theValues[theIt++];
496 Standard_Real aFirstZ = (Standard_Real) theValues[theIt++];
499 Standard_Real aSecondX = (Standard_Real) theValues[theIt++];
500 Standard_Real aSecondY = (Standard_Real) theValues[theIt++];
501 Standard_Real aSecondZ = (Standard_Real) theValues[theIt++];
504 Standard_Real aCenterX = (Standard_Real) theValues[theIt++];
505 Standard_Real aCenterY = (Standard_Real) theValues[theIt++];
506 Standard_Real aCenterZ = (Standard_Real) theValues[theIt++];
508 FirstPoint = gp_Pnt( aFirstX, aFirstY, aFirstZ );
509 SecondPoint = gp_Pnt( aSecondX, aSecondY, aSecondZ );
510 CenterPoint = gp_Pnt( aCenterX, aCenterY, aCenterZ );
513 //=================================================================================
514 // function : Angle::operator ==
516 //=================================================================================
517 bool GEOMGUI_DimensionProperty::Angle::operator == (const Angle& theOther) const
519 if ( FirstPoint.X() != theOther.FirstPoint.X()
520 || FirstPoint.Y() != theOther.FirstPoint.Y()
521 || FirstPoint.Z() != theOther.FirstPoint.Z()
522 || SecondPoint.X() != theOther.SecondPoint.X()
523 || SecondPoint.Y() != theOther.SecondPoint.Y()
524 || SecondPoint.Z() != theOther.SecondPoint.Z()
525 || CenterPoint.X() != theOther.CenterPoint.X()
526 || CenterPoint.Y() != theOther.CenterPoint.Y()
527 || CenterPoint.Z() != theOther.CenterPoint.Z() )
532 if ( Flyout != theOther.Flyout
533 || TextHPos != theOther.TextHPos
534 || TextVPos != theOther.TextVPos
535 || ArrowPos != theOther.ArrowPos )
543 //=================================================================================
544 // function : Constructor
546 //=================================================================================
547 GEOMGUI_DimensionProperty::GEOMGUI_DimensionProperty()
551 //=================================================================================
552 // function : Copy constructor
554 //=================================================================================
555 GEOMGUI_DimensionProperty::GEOMGUI_DimensionProperty( const GEOMGUI_DimensionProperty& theOther )
557 const VectorOfVisibility& aOtherVis = theOther.myVisibility;
558 const VectorOfNames& aOtherNames = theOther.myNames;
559 const VectorOfRecords& aOtherRecords = theOther.myRecords;
561 VectorOfVisibility::const_iterator aVisIt = aOtherVis.constBegin();
562 VectorOfNames::const_iterator aNamesIt = aOtherNames.constBegin();
563 VectorOfRecords::const_iterator aRecordIt = aOtherRecords.constBegin();
564 for ( ; aRecordIt != aOtherRecords.constEnd(); ++aVisIt, ++aNamesIt, ++aRecordIt )
566 RecordPtr aNewRecord;
567 const RecordPtr& aRecord = *aRecordIt;
568 switch( aRecord->Type() )
570 case DimensionType_Length :
571 aNewRecord = RecordPtr( new Length( *aRecord->AsLength() ) );
574 case DimensionType_Diameter :
575 aNewRecord = RecordPtr( new Diameter( *aRecord->AsDiameter() ) );
578 case DimensionType_Angle :
579 aNewRecord = RecordPtr( new Angle( *aRecord->AsAngle() ) );
583 myVisibility.append( *aVisIt );
584 myNames.append( *aNamesIt );
585 myRecords.append( aNewRecord );
589 //=================================================================================
590 // function : Init constructor
592 //=================================================================================
593 GEOMGUI_DimensionProperty::GEOMGUI_DimensionProperty( SalomeApp_Study* theStudy, const std::string& theEntry )
595 LoadFromAttribute( theStudy, theEntry );
598 //=================================================================================
599 // function : Init constructor
601 //=================================================================================
602 GEOMGUI_DimensionProperty::GEOMGUI_DimensionProperty( const QString& theProperty )
604 QRegExp aRegExpItemGroups( PATTERN_ITEM_GROUP );
605 QRegExp aRegExpItem( "^" + PATTERN_ITEM + "$" );
606 aRegExpItemGroups.setMinimal( true );
607 aRegExpItem.setMinimal( true );
610 while ( ( aPos = aRegExpItemGroups.indexIn( theProperty, aPos ) ) != -1 )
612 aPos += aRegExpItemGroups.matchedLength();
614 QString aStrItem = aRegExpItemGroups.cap(1);
616 if ( aRegExpItem.indexIn( aStrItem ) < 0 )
622 QString aStrName = aRegExpItem.cap( 1 );
623 QString aStrVisible = aRegExpItem.cap( 2 );
624 QString aStrType = aRegExpItem.cap( 3 );
625 QString aStrValues = aRegExpItem.cap( 4 );
628 aStrName.replace( "::", ":" );
629 bool isVisible = aStrVisible.toInt() != 0;
630 int aType = aStrType.toInt();
635 case DimensionType_Length : aRecord = RecordPtr( new Length ); break;
636 case DimensionType_Diameter : aRecord = RecordPtr( new Diameter ); break;
637 case DimensionType_Angle : aRecord = RecordPtr( new Angle ); break;
642 QRegExp aRegExpValues;
645 case DimensionType_Length : aRegExpValues = QRegExp( "^" + PATTERN_LENGTH + "$" ); break;
646 case DimensionType_Diameter : aRegExpValues = QRegExp( "^" + PATTERN_DIAMETER + "$" ); break;
647 case DimensionType_Angle : aRegExpValues = QRegExp( "^" + PATTERN_ANGLE + "$" ); break;
650 aRegExpValues.setMinimal(true);
652 if ( aRegExpValues.indexIn( aStrValues ) < 0 )
657 std::vector<double> aValues;
659 QStringList aStrListOfValues = aRegExpValues.capturedTexts();
660 QStringList::Iterator aStrListOfValuesIt = aStrListOfValues.begin();
661 ++aStrListOfValuesIt; // skip first capture
662 for ( ; aStrListOfValuesIt != aStrListOfValues.end(); ++aStrListOfValuesIt )
664 aValues.push_back( (*aStrListOfValuesIt).toDouble() );
669 aRecord->FromValues( aValueIt, aValues );
671 myVisibility.append( isVisible );
672 myNames.append( aStrName );
673 myRecords.append( aRecord );
677 //=================================================================================
678 // function : Destructor
680 //=================================================================================
681 GEOMGUI_DimensionProperty::~GEOMGUI_DimensionProperty()
685 //=================================================================================
686 // function : operator QVariant()
688 //=================================================================================
689 GEOMGUI_DimensionProperty::operator QVariant() const
692 aQVariant.setValue( *this );
696 //=================================================================================
697 // function : operator QString()
699 //=================================================================================
700 GEOMGUI_DimensionProperty::operator QString() const
704 VectorOfVisibility::ConstIterator aVisibilityIt = myVisibility.constBegin();
705 VectorOfRecords::ConstIterator aRecordIt = myRecords.constBegin();
706 VectorOfNames::ConstIterator aNameIt = myNames.constBegin();
707 for ( ; aRecordIt != myRecords.constEnd(); ++aRecordIt, ++aNameIt, ++aVisibilityIt )
709 QString aName = *aNameIt;
710 const bool& isVisible = *aVisibilityIt;
711 const RecordPtr& aRecord = *aRecordIt;
714 std::vector<double> aPacked;
715 aRecord->ToValues( aPacked );
717 // put values into pattern
718 QString aStringValues;
719 switch ( aRecord->Type() )
721 case DimensionType_Length : aStringValues = PATTERN_LENGTH; break;
722 case DimensionType_Diameter : aStringValues = PATTERN_DIAMETER; break;
723 case DimensionType_Angle : aStringValues = PATTERN_ANGLE; break;
728 aStringValues.remove("\\");
731 for ( ; it < aPacked.size(); ++it )
733 int aNextPos = aStringValues.indexOf("(.*)");
736 break; // invalid pattern
739 aStringValues.replace( aNextPos, 4, QString::number( aPacked.at(it) ) );
742 if ( it < aPacked.size() )
744 continue; // invalid pattern
747 // replace all ':' to '::' for pattern matching
748 aName.replace(":", "::");
751 QString("{ Name=") + aName +
752 QString(":") + QString("Visible=") + QString::number( isVisible ? 1 : 0 ) +
753 QString(":") + QString("Type=") + QString::number( (int) aRecord->Type() ) +
754 QString(":") + aStringValues + QString(" }") );
757 return anItems.join( ":" );
760 //=================================================================================
761 // function : operator ==
763 //=================================================================================
764 bool GEOMGUI_DimensionProperty::operator == (const GEOMGUI_DimensionProperty& theOther) const
766 if ( myVisibility.size() != theOther.myVisibility.size()
767 || myNames.size() != theOther.myNames.size()
768 || myRecords.size() != theOther.myRecords.size() )
773 for ( int it = 0; it < myRecords.size(); ++it )
775 if ( myVisibility[it] != theOther.myVisibility[it] )
780 if ( myNames[it] != theOther.myNames[it] )
785 const RecordPtr& aRecord = myRecords[it];
786 const RecordPtr& aOtherRecord = theOther.myRecords[it];
787 if ( aRecord->Type() != aOtherRecord->Type() )
792 switch ( aRecord->Type() )
794 case DimensionType_Length:
795 if ( (*aRecord->AsLength()) != (*aOtherRecord->AsLength()) )
801 case DimensionType_Diameter:
802 if ( (*aRecord->AsDiameter()) != (*aOtherRecord->AsDiameter()) )
808 case DimensionType_Angle:
809 if ( (*aRecord->AsAngle()) != (*aOtherRecord->AsAngle()) )
820 //=================================================================================
821 // function : GetNumber
823 //=================================================================================
824 int GEOMGUI_DimensionProperty::GetNumber() const
826 return myRecords.size();
829 //=================================================================================
830 // function : AddRecord
832 //=================================================================================
833 void GEOMGUI_DimensionProperty::AddRecord( const Handle(AIS_Dimension)& theIO, const gp_Ax3& theLCS )
835 RecordPtr aNewRecord;
837 int aType = TypeFromIO( theIO );
841 case DimensionType_Length :
843 Handle(AIS_LengthDimension) aLength =
844 Handle(AIS_LengthDimension)::DownCast( theIO );
846 aNewRecord = RecordPtr( new Length() );
847 aNewRecord->AsLength()->Init( aLength, theLCS );
851 case DimensionType_Diameter :
853 Handle(AIS_DiameterDimension) aDiam =
854 Handle(AIS_DiameterDimension)::DownCast( theIO );
856 aNewRecord = RecordPtr( new Diameter() );
857 aNewRecord->AsDiameter()->Init( aDiam, theLCS );
861 case DimensionType_Angle :
863 Handle(AIS_AngleDimension) anAngle =
864 Handle(AIS_AngleDimension)::DownCast( theIO );
866 aNewRecord = RecordPtr( new Angle() );
867 aNewRecord->AsAngle()->Init( anAngle, theLCS );
871 myVisibility.append( true );
872 myNames.append( QString() );
873 myRecords.append( aNewRecord );
876 //=================================================================================
877 // function : AddRecord
879 //=================================================================================
880 void GEOMGUI_DimensionProperty::AddRecord( const RecordPtr& theRecord )
882 myVisibility.append( true );
883 myNames.append( QString() );
884 myRecords.append( theRecord );
887 //=================================================================================
888 // function : RemoveRecord
890 //=================================================================================
891 void GEOMGUI_DimensionProperty::RemoveRecord( const int theIndex )
893 myNames.remove( theIndex );
894 myVisibility.remove( theIndex );
895 myRecords.remove( theIndex );
898 //=================================================================================
901 //=================================================================================
902 void GEOMGUI_DimensionProperty::Clear()
905 myVisibility.clear();
909 //=================================================================================
910 // function : SetRecord
912 //=================================================================================
913 void GEOMGUI_DimensionProperty::SetRecord( const int theIndex,
914 const Handle(AIS_Dimension)& theIO,
915 const gp_Ax3& theLCS )
917 int aType = TypeFromIO( theIO );
919 RecordPtr& aChangeRecord = myRecords[theIndex];
923 case DimensionType_Length :
925 Handle(AIS_LengthDimension) aLength =
926 Handle(AIS_LengthDimension)::DownCast( theIO );
928 aChangeRecord = RecordPtr( new Length() );
929 aChangeRecord->AsLength()->Init( aLength, theLCS );
933 case DimensionType_Diameter :
935 Handle(AIS_DiameterDimension) aDiam =
936 Handle(AIS_DiameterDimension)::DownCast( theIO );
938 aChangeRecord = RecordPtr( new Diameter() );
939 aChangeRecord->AsDiameter()->Init( aDiam, theLCS );
943 case DimensionType_Angle :
945 Handle(AIS_AngleDimension) anAngle =
946 Handle(AIS_AngleDimension)::DownCast( theIO );
948 aChangeRecord = RecordPtr( new Angle() );
949 aChangeRecord->AsAngle()->Init( anAngle, theLCS );
954 //=================================================================================
955 // function : SetRecord
957 //=================================================================================
958 void GEOMGUI_DimensionProperty::SetRecord( const int theIndex, const RecordPtr& theRecord )
960 myRecords[theIndex] = theRecord;
963 //=================================================================================
964 // function : GetRecord
966 //=================================================================================
967 const GEOMGUI_DimensionProperty::RecordPtr& GEOMGUI_DimensionProperty::GetRecord( const int theIndex ) const
969 return myRecords[theIndex];
972 //=================================================================================
973 // function : IsVisible
975 //=================================================================================
976 bool GEOMGUI_DimensionProperty::IsVisible( const int theIndex ) const
978 return myVisibility[theIndex];
981 //=================================================================================
982 // function : SetVisible
984 //=================================================================================
985 void GEOMGUI_DimensionProperty::SetVisible( const int theIndex, const bool theIsVisible )
987 myVisibility[theIndex] = theIsVisible;
990 //=================================================================================
991 // function : GetName
993 //=================================================================================
994 QString GEOMGUI_DimensionProperty::GetName( const int theIndex ) const
996 return myNames[theIndex];
999 //=================================================================================
1000 // function : SetName
1002 //=================================================================================
1003 void GEOMGUI_DimensionProperty::SetName( const int theIndex, const QString &theName )
1005 myNames[theIndex] = theName;
1008 //=================================================================================
1009 // function : GetType
1011 //=================================================================================
1012 int GEOMGUI_DimensionProperty::GetType( const int theIndex ) const
1014 return myRecords[theIndex]->Type();
1017 //=================================================================================
1018 // function : LoadFromAttribute
1020 //=================================================================================
1021 void GEOMGUI_DimensionProperty::LoadFromAttribute( SalomeApp_Study* theStudy,
1022 const std::string& theEntry )
1026 _PTR(SObject) aSObj = theStudy->studyDS()->FindObjectID( theEntry );
1032 _PTR(StudyBuilder) aBuilder = theStudy->studyDS()->NewBuilder();
1034 _PTR(GenericAttribute) aSeekAtt;
1035 _PTR(AttributeTableOfReal) aRecordsAtt;
1037 if ( !aSObj->FindAttribute( aSeekAtt, "AttributeTableOfReal" ) )
1042 aRecordsAtt = aSeekAtt;
1044 for ( int aRecordIt = 1; aRecordIt <= aRecordsAtt->GetNbColumns(); ++aRecordIt )
1046 std::vector<double> aPacked = aRecordsAtt->GetColumn( aRecordIt );
1050 QString aName( aRecordsAtt->GetColumnTitle( aRecordIt ).c_str() );
1056 bool isVisible = (bool) aPacked[it++];
1059 int aType = (int) aPacked[it++];
1063 case DimensionType_Length : aRecord = RecordPtr( new Length ); break;
1064 case DimensionType_Diameter : aRecord = RecordPtr( new Diameter ); break;
1065 case DimensionType_Angle : aRecord = RecordPtr( new Angle ); break;
1067 aRecord->FromValues(it, aPacked);
1069 myVisibility.append( isVisible );
1070 myNames.append( aName );
1071 myRecords.append( aRecord );
1075 //=================================================================================
1076 // function : SaveToAttribute
1078 //=================================================================================
1079 void GEOMGUI_DimensionProperty::SaveToAttribute( SalomeApp_Study *theStudy,
1080 const std::string &theEntry )
1082 _PTR(SObject) aSObj = theStudy->studyDS()->FindObjectID( theEntry );
1088 _PTR(StudyBuilder) aBuilder = theStudy->studyDS()->NewBuilder();
1090 _PTR(AttributeTableOfReal) aRecordsAtt;
1092 aRecordsAtt = aBuilder->FindOrCreateAttribute( aSObj, "AttributeTableOfReal" );
1093 aRecordsAtt->SetNbColumns( 0 );
1095 for ( int it = 0; it < myRecords.size(); ++it )
1097 bool aVisibility = myVisibility[it];
1098 QString& aName = myNames[it];
1099 RecordPtr& aRecord = myRecords[it];
1101 std::vector<double> aPacked;
1104 aPacked.push_back( (double) aVisibility );
1107 aPacked.push_back( (double) aRecord->Type() );
1110 aRecord->ToValues( aPacked );
1112 aRecordsAtt->AddColumn( aPacked );
1113 aRecordsAtt->SetColumnTitle( it + 1, aName.toStdString() );
1117 //=================================================================================
1118 // function : TypeFromIO
1120 //=================================================================================
1121 int GEOMGUI_DimensionProperty::TypeFromIO( const Handle(AIS_Dimension)& theIO ) const
1123 if ( theIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) ) )
1125 return DimensionType_Length;
1128 if ( theIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
1130 return DimensionType_Diameter;
1133 if ( theIO->IsKind( STANDARD_TYPE( AIS_AngleDimension ) ) )
1135 return DimensionType_Angle;
1138 Standard_ProgramError::Raise( "unsupported dimension type" );