1 // Copyright (C) 2007-2021 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"
29 #include <Basics_OCCTVersion.hxx>
32 #include <Standard_ProgramError.hxx>
33 #include <gp_Trsf.hxx>
35 #include <SalomeApp_Application.h>
37 // Static patterns for casting value-to-string & value-from-string. The patterns are:
38 // ITEM: { name[string] : visibility : type : values[composite] };
39 // PLANE: a[float] : b[float] : c[float] : d[float]
40 // PROPS: flyout[float] : text h pos[int] : text v pos[int] : arrow pos[int]
41 // XYZ: x [float] : y[float] : z[float]
42 // FLOAT: value [float]
45 static const QString PATTERN_ITEM_GROUP = "\\{ (Name=(?::{2,}|.)*:(?!:)Visible=.*:Type=.*:.*) \\}";
46 static const QString PATTERN_ITEM = "Name=((?::{2,}|.)*):(?!:)Visible=(\\d{1}):Type=(\\d{1}):(.*)";
47 static const QString PATTERN_PLANE = "Plane=\\{(.*):(.*):(.*):(.*)\\}";
48 static const QString PATTERN_PROPS = "Flyout=(.*):TextH=(.*):TextV=(.*):Arrow=(.*)";
49 static const QString PATTERN_XYZ = "%1=\\{(.*):(.*):(.*)\\}";
50 static const QString PATTERN_FLOAT = "%1=(.*)";
52 static const QString PATTERN_LENGTH =
55 PATTERN_XYZ.arg( "Point1" ) + ":" +
56 PATTERN_XYZ.arg( "Point2" );
58 static const QString PATTERN_DIAMETER =
61 PATTERN_XYZ.arg( "Position" ) + ":" +
62 PATTERN_XYZ.arg( "NDir" ) + ":" +
63 PATTERN_XYZ.arg( "XDir" ) + ":" +
64 PATTERN_FLOAT.arg( "Radius" );
66 static const QString PATTERN_ANGLE =
68 PATTERN_XYZ.arg( "Point1" ) + ":" +
69 PATTERN_XYZ.arg( "Point2" ) + ":" +
70 PATTERN_XYZ.arg( "Point3" );
73 //=================================================================================
74 // function : Length::Init
76 //=================================================================================
77 #if OCC_VERSION_LARGE >= 0x070400ff
78 void GEOMGUI_DimensionProperty::Length::Init( const Handle(PrsDim_LengthDimension)& theIO, const gp_Ax3& theLCS )
80 void GEOMGUI_DimensionProperty::Length::Init( const Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS )
84 aFromLCS.SetTransformation( gp_Ax3(), theLCS );
86 FirstPoint = theIO->FirstPoint().Transformed( aFromLCS );
87 SecondPoint = theIO->SecondPoint().Transformed( aFromLCS );
88 Plane = theIO->GetPlane().Transformed( aFromLCS );
89 Flyout = theIO->GetFlyout();
90 TextHPos = theIO->DimensionAspect()->TextHorizontalPosition();
91 TextVPos = theIO->DimensionAspect()->TextVerticalPosition();
92 ArrowPos = theIO->DimensionAspect()->ArrowOrientation();
95 //=================================================================================
96 // function : Length::Update
98 //=================================================================================
99 #if OCC_VERSION_LARGE >= 0x070400ff
100 void GEOMGUI_DimensionProperty::Length::Update( Handle(PrsDim_LengthDimension)& theIO, const gp_Ax3& theLCS )
102 void GEOMGUI_DimensionProperty::Length::Update( Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS )
106 aToLCS.SetTransformation( theLCS, gp_Ax3() );
108 gp_Pnt aPoint1 = FirstPoint.Transformed( aToLCS );
109 gp_Pnt aPoint2 = SecondPoint.Transformed( aToLCS );
110 gp_Pln aPlane = Plane.Transformed( aToLCS );
112 theIO->SetMeasuredGeometry( aPoint1, aPoint2, aPlane );
113 theIO->SetFlyout( Flyout );
115 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
116 aStyle->SetTextHorizontalPosition( TextHPos );
117 aStyle->SetTextVerticalPosition( TextVPos );
118 aStyle->SetArrowOrientation( ArrowPos );
119 theIO->SetDimensionAspect( aStyle );
122 //=================================================================================
123 // function : Length::ToValues
125 //=================================================================================
126 void GEOMGUI_DimensionProperty::Length::ToValues(std::vector<double>& theValues) const
128 // custom plane [2,3,4,5]
129 Standard_Real A, B, C, D;
130 Plane.Coefficients( A, B, C, D );
131 theValues.push_back( (double) A );
132 theValues.push_back( (double) B );
133 theValues.push_back( (double) C );
134 theValues.push_back( (double) D );
137 theValues.push_back( (double) Flyout );
140 theValues.push_back( (double) TextHPos );
141 theValues.push_back( (double) TextVPos );
144 theValues.push_back( (double) ArrowPos );
146 // point 1 [10,11,12]
147 theValues.push_back( (double) FirstPoint.X() );
148 theValues.push_back( (double) FirstPoint.Y() );
149 theValues.push_back( (double) FirstPoint.Z() );
151 // point 2 [13,14,15]
152 theValues.push_back( (double) SecondPoint.X() );
153 theValues.push_back( (double) SecondPoint.Y() );
154 theValues.push_back( (double) SecondPoint.Z() );
157 //=================================================================================
158 // function : Length::FromValues
160 //=================================================================================
161 void GEOMGUI_DimensionProperty::Length::FromValues(int& theIt, const std::vector<double>& theValues)
163 // custom plane [2,3,4,5]
164 Standard_Real A = (Standard_Real) theValues[theIt++];
165 Standard_Real B = (Standard_Real) theValues[theIt++];
166 Standard_Real C = (Standard_Real) theValues[theIt++];
167 Standard_Real D = (Standard_Real) theValues[theIt++];
168 Plane = gp_Pln( A, B, C, D );
171 Flyout = (Standard_Real) theValues[theIt++];
174 TextHPos = (Prs3d_DimensionTextHorizontalPosition)(int)theValues[theIt++];
175 TextVPos = (Prs3d_DimensionTextVerticalPosition) (int)theValues[theIt++];
178 ArrowPos = (Prs3d_DimensionArrowOrientation) (int)theValues[theIt++];
180 // point 1 [10,11,12]
181 Standard_Real aFirstX = theValues[theIt++];
182 Standard_Real aFirstY = theValues[theIt++];
183 Standard_Real aFirstZ = theValues[theIt++];
184 FirstPoint = gp_Pnt( aFirstX, aFirstY, aFirstZ );
186 // point 2 [13,14,15]
187 Standard_Real aSecondX = theValues[theIt++];
188 Standard_Real aSecondY = theValues[theIt++];
189 Standard_Real aSecondZ = theValues[theIt++];
190 SecondPoint = gp_Pnt( aSecondX, aSecondY, aSecondZ );
193 //=================================================================================
194 // function : Length::operator ==
196 //=================================================================================
197 bool GEOMGUI_DimensionProperty::Length::operator == (const Length& theOther) const
199 if ( FirstPoint.X() != theOther.FirstPoint.X()
200 || FirstPoint.Y() != theOther.FirstPoint.Y()
201 || FirstPoint.Z() != theOther.FirstPoint.Z()
202 || SecondPoint.X() != theOther.SecondPoint.X()
203 || SecondPoint.Y() != theOther.SecondPoint.Y()
204 || SecondPoint.Z() != theOther.SecondPoint.Z() )
209 if ( Plane.Location().X() != theOther.Plane.Location().X()
210 || Plane.Location().Y() != theOther.Plane.Location().Y()
211 || Plane.Location().Z() != theOther.Plane.Location().Z()
212 || Plane.Axis().Direction().X() != theOther.Plane.Axis().Direction().X()
213 || Plane.Axis().Direction().Y() != theOther.Plane.Axis().Direction().Y()
214 || Plane.Axis().Direction().Z() != theOther.Plane.Axis().Direction().Z() )
219 if ( Flyout != theOther.Flyout
220 || TextHPos != theOther.TextHPos
221 || TextVPos != theOther.TextVPos
222 || ArrowPos != theOther.ArrowPos )
230 //=================================================================================
231 // function : Diameter::Init
233 //=================================================================================
234 void GEOMGUI_DimensionProperty::Diameter::Init( const Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS )
237 aFromLCS.SetTransformation( gp_Ax3(), theLCS );
239 Circle = theIO->Circle().Transformed( aFromLCS );
240 Plane = theIO->GetPlane().Transformed( aFromLCS );
241 Flyout = theIO->GetFlyout();
242 TextHPos = theIO->DimensionAspect()->TextHorizontalPosition();
243 TextVPos = theIO->DimensionAspect()->TextVerticalPosition();
244 ArrowPos = theIO->DimensionAspect()->ArrowOrientation();
247 //=================================================================================
248 // function : Diameter::Update
250 //=================================================================================
251 void GEOMGUI_DimensionProperty::Diameter::Update( Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS )
254 aToLCS.SetTransformation( theLCS, gp_Ax3() );
256 gp_Circ aCircle = Circle.Transformed( aToLCS );
257 gp_Pln aPlane = Plane.Transformed( aToLCS );
259 Standard_Boolean isParallel =
260 aCircle.Axis().Direction().IsParallel( aPlane.Axis().Direction(), Precision::Angular() );
264 theIO->UnsetCustomPlane();
265 theIO->SetMeasuredGeometry( aCircle );
269 theIO->SetCustomPlane( aPlane );
270 theIO->SetMeasuredGeometry( aCircle );
273 theIO->SetFlyout( Flyout );
275 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
276 aStyle->SetTextHorizontalPosition( TextHPos );
277 aStyle->SetTextVerticalPosition( TextVPos );
278 aStyle->SetArrowOrientation( ArrowPos );
279 theIO->SetDimensionAspect( aStyle );
282 //=================================================================================
283 // function : Diameter::ToValues
285 //=================================================================================
286 void GEOMGUI_DimensionProperty::Diameter::ToValues(std::vector<double>& theValues) const
288 // custom plane [2,3,4,5]
289 Standard_Real A, B, C, D;
290 Plane.Coefficients( A, B, C, D );
291 theValues.push_back( (double) A );
292 theValues.push_back( (double) B );
293 theValues.push_back( (double) C );
294 theValues.push_back( (double) D );
297 theValues.push_back( (double) Flyout );
300 theValues.push_back( (double) TextHPos );
301 theValues.push_back( (double) TextVPos );
304 theValues.push_back( (double) ArrowPos );
306 // circle location [10,11,12]
307 theValues.push_back( (double) Circle.Location().X() );
308 theValues.push_back( (double) Circle.Location().Y() );
309 theValues.push_back( (double) Circle.Location().Z() );
311 // circle normal [13,14,15]
312 theValues.push_back( (double) Circle.Axis().Direction().X() );
313 theValues.push_back( (double) Circle.Axis().Direction().Y() );
314 theValues.push_back( (double) Circle.Axis().Direction().Z() );
316 // x-direction [16,17,18]
317 theValues.push_back( (double) Circle.XAxis().Direction().X() );
318 theValues.push_back( (double) Circle.XAxis().Direction().Y() );
319 theValues.push_back( (double) Circle.XAxis().Direction().Z() );
322 theValues.push_back( (double) Circle.Radius() );
325 //=================================================================================
326 // function : Diameter::FromValues
328 //=================================================================================
329 void GEOMGUI_DimensionProperty::Diameter::FromValues(int& theIt, const std::vector<double>& theValues)
331 // custom plane [2,3,4,5]
332 Standard_Real A = (Standard_Real) theValues[theIt++];
333 Standard_Real B = (Standard_Real) theValues[theIt++];
334 Standard_Real C = (Standard_Real) theValues[theIt++];
335 Standard_Real D = (Standard_Real) theValues[theIt++];
336 Plane = gp_Pln( A, B, C, D );
339 Flyout = (Standard_Real) theValues[theIt++];
342 TextHPos = (Prs3d_DimensionTextHorizontalPosition)(int)theValues[theIt++];
343 TextVPos = (Prs3d_DimensionTextVerticalPosition) (int)theValues[theIt++];
346 ArrowPos = (Prs3d_DimensionArrowOrientation) (int)theValues[theIt++];
348 // circle location [10,11,12]
349 Standard_Real aLocX = (Standard_Real) theValues[theIt++];
350 Standard_Real aLocY = (Standard_Real) theValues[theIt++];
351 Standard_Real aLocZ = (Standard_Real) theValues[theIt++];
353 // circle normal [13,14,15]
354 Standard_Real aNormX = (Standard_Real) theValues[theIt++];
355 Standard_Real aNormY = (Standard_Real) theValues[theIt++];
356 Standard_Real aNormZ = (Standard_Real) theValues[theIt++];
358 // x-direction [16,17,18]
359 Standard_Real aXDirX = (Standard_Real) theValues[theIt++];
360 Standard_Real aXDirY = (Standard_Real) theValues[theIt++];
361 Standard_Real aXDirZ = (Standard_Real) theValues[theIt++];
364 Standard_Real aRadius = (Standard_Real) theValues[theIt++];
366 gp_Ax2 anAx( gp_Pnt( aLocX, aLocY, aLocZ ),
367 gp_Dir( aNormX, aNormY, aNormZ ),
368 gp_Dir( aXDirX, aXDirY, aXDirZ ) );
370 Circle = gp_Circ( anAx, aRadius );
373 //=================================================================================
374 // function : Diameter::operator ==
376 //=================================================================================
377 bool GEOMGUI_DimensionProperty::Diameter::operator == (const Diameter& theOther) const
379 if ( Circle.Location().X() != theOther.Circle.Location().X()
380 || Circle.Location().Y() != theOther.Circle.Location().Y()
381 || Circle.Location().Z() != theOther.Circle.Location().Z()
382 || Circle.Axis().Direction().X() != theOther.Circle.Axis().Direction().X()
383 || Circle.Axis().Direction().Y() != theOther.Circle.Axis().Direction().Y()
384 || Circle.Axis().Direction().Z() != theOther.Circle.Axis().Direction().Z()
385 || Circle.XAxis().Direction().X() != theOther.Circle.XAxis().Direction().X()
386 || Circle.XAxis().Direction().Y() != theOther.Circle.XAxis().Direction().Y()
387 || Circle.XAxis().Direction().Z() != theOther.Circle.XAxis().Direction().Z()
388 || Circle.Radius() != theOther.Circle.Radius() )
393 if ( Plane.Location().X() != theOther.Plane.Location().X()
394 || Plane.Location().Y() != theOther.Plane.Location().Y()
395 || Plane.Location().Z() != theOther.Plane.Location().Z()
396 || Plane.Axis().Direction().X() != theOther.Plane.Axis().Direction().X()
397 || Plane.Axis().Direction().Y() != theOther.Plane.Axis().Direction().Y()
398 || Plane.Axis().Direction().Z() != theOther.Plane.Axis().Direction().Z() )
403 if ( Flyout != theOther.Flyout
404 || TextHPos != theOther.TextHPos
405 || TextVPos != theOther.TextVPos
406 || ArrowPos != theOther.ArrowPos )
414 //=================================================================================
415 // function : Angle::Init
417 //=================================================================================
418 void GEOMGUI_DimensionProperty::Angle::Init( const Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS )
421 aFromLCS.SetTransformation( gp_Ax3(), theLCS );
423 FirstPoint = theIO->FirstPoint().Transformed( aFromLCS );
424 SecondPoint = theIO->SecondPoint().Transformed( aFromLCS );
425 CenterPoint = theIO->CenterPoint().Transformed( aFromLCS );
426 Flyout = theIO->GetFlyout();
427 TextHPos = theIO->DimensionAspect()->TextHorizontalPosition();
428 TextVPos = theIO->DimensionAspect()->TextVerticalPosition();
429 ArrowPos = theIO->DimensionAspect()->ArrowOrientation();
432 //=================================================================================
433 // function : Angle::Update
435 //=================================================================================
436 void GEOMGUI_DimensionProperty::Angle::Update( Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS )
439 aToLCS.SetTransformation( theLCS, gp_Ax3() );
441 gp_Pnt aPoint1 = FirstPoint.Transformed( aToLCS );
442 gp_Pnt aPoint2 = CenterPoint.Transformed( aToLCS );
443 gp_Pnt aPoint3 = SecondPoint.Transformed( aToLCS );
445 theIO->SetMeasuredGeometry( aPoint1, aPoint2, aPoint3 );
446 theIO->SetFlyout( Flyout );
448 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
449 aStyle->SetTextHorizontalPosition( TextHPos );
450 aStyle->SetTextVerticalPosition( TextVPos );
451 aStyle->SetArrowOrientation( ArrowPos );
452 theIO->SetDimensionAspect( aStyle );
455 //=================================================================================
456 // function : Angle::ToValues
458 //=================================================================================
459 void GEOMGUI_DimensionProperty::Angle::ToValues(std::vector<double>& theValues) const
462 theValues.push_back( (double) Flyout );
465 theValues.push_back( (double) TextHPos );
466 theValues.push_back( (double) TextVPos );
469 theValues.push_back( (double) ArrowPos );
472 theValues.push_back( (double) FirstPoint.X() );
473 theValues.push_back( (double) FirstPoint.Y() );
474 theValues.push_back( (double) FirstPoint.Z() );
477 theValues.push_back( (double) SecondPoint.X() );
478 theValues.push_back( (double) SecondPoint.Y() );
479 theValues.push_back( (double) SecondPoint.Z() );
482 theValues.push_back( (double) CenterPoint.X() );
483 theValues.push_back( (double) CenterPoint.Y() );
484 theValues.push_back( (double) CenterPoint.Z() );
487 //=================================================================================
488 // function : Angle::FromValues
490 //=================================================================================
491 void GEOMGUI_DimensionProperty::Angle::FromValues(int& theIt, const std::vector<double>& theValues)
494 Flyout = (Standard_Real) theValues[theIt++];
497 TextHPos = (Prs3d_DimensionTextHorizontalPosition)(int)theValues[theIt++];
498 TextVPos = (Prs3d_DimensionTextVerticalPosition) (int)theValues[theIt++];
501 ArrowPos = (Prs3d_DimensionArrowOrientation) (int)theValues[theIt++];
504 Standard_Real aFirstX = (Standard_Real) theValues[theIt++];
505 Standard_Real aFirstY = (Standard_Real) theValues[theIt++];
506 Standard_Real aFirstZ = (Standard_Real) theValues[theIt++];
509 Standard_Real aSecondX = (Standard_Real) theValues[theIt++];
510 Standard_Real aSecondY = (Standard_Real) theValues[theIt++];
511 Standard_Real aSecondZ = (Standard_Real) theValues[theIt++];
514 Standard_Real aCenterX = (Standard_Real) theValues[theIt++];
515 Standard_Real aCenterY = (Standard_Real) theValues[theIt++];
516 Standard_Real aCenterZ = (Standard_Real) theValues[theIt++];
518 FirstPoint = gp_Pnt( aFirstX, aFirstY, aFirstZ );
519 SecondPoint = gp_Pnt( aSecondX, aSecondY, aSecondZ );
520 CenterPoint = gp_Pnt( aCenterX, aCenterY, aCenterZ );
523 //=================================================================================
524 // function : Angle::operator ==
526 //=================================================================================
527 bool GEOMGUI_DimensionProperty::Angle::operator == (const Angle& theOther) const
529 if ( FirstPoint.X() != theOther.FirstPoint.X()
530 || FirstPoint.Y() != theOther.FirstPoint.Y()
531 || FirstPoint.Z() != theOther.FirstPoint.Z()
532 || SecondPoint.X() != theOther.SecondPoint.X()
533 || SecondPoint.Y() != theOther.SecondPoint.Y()
534 || SecondPoint.Z() != theOther.SecondPoint.Z()
535 || CenterPoint.X() != theOther.CenterPoint.X()
536 || CenterPoint.Y() != theOther.CenterPoint.Y()
537 || CenterPoint.Z() != theOther.CenterPoint.Z() )
542 if ( Flyout != theOther.Flyout
543 || TextHPos != theOther.TextHPos
544 || TextVPos != theOther.TextVPos
545 || ArrowPos != theOther.ArrowPos )
553 //=================================================================================
554 // function : Constructor
556 //=================================================================================
557 GEOMGUI_DimensionProperty::GEOMGUI_DimensionProperty()
561 //=================================================================================
562 // function : Copy constructor
564 //=================================================================================
565 GEOMGUI_DimensionProperty::GEOMGUI_DimensionProperty( const GEOMGUI_DimensionProperty& theOther )
567 const VectorOfVisibility& aOtherVis = theOther.myVisibility;
568 const VectorOfNames& aOtherNames = theOther.myNames;
569 const VectorOfRecords& aOtherRecords = theOther.myRecords;
571 VectorOfVisibility::const_iterator aVisIt = aOtherVis.constBegin();
572 VectorOfNames::const_iterator aNamesIt = aOtherNames.constBegin();
573 VectorOfRecords::const_iterator aRecordIt = aOtherRecords.constBegin();
574 for ( ; aRecordIt != aOtherRecords.constEnd(); ++aVisIt, ++aNamesIt, ++aRecordIt )
576 RecordPtr aNewRecord;
577 const RecordPtr& aRecord = *aRecordIt;
578 switch( aRecord->Type() )
580 case DimensionType_Length :
581 aNewRecord = RecordPtr( new Length( *aRecord->AsLength() ) );
584 case DimensionType_Diameter :
585 aNewRecord = RecordPtr( new Diameter( *aRecord->AsDiameter() ) );
588 case DimensionType_Angle :
589 aNewRecord = RecordPtr( new Angle( *aRecord->AsAngle() ) );
593 myVisibility.append( *aVisIt );
594 myNames.append( *aNamesIt );
595 myRecords.append( aNewRecord );
599 //=================================================================================
600 // function : Init constructor
602 //=================================================================================
603 GEOMGUI_DimensionProperty::GEOMGUI_DimensionProperty( const std::string& theEntry )
605 LoadFromAttribute( theEntry );
608 //=================================================================================
609 // function : Init constructor
611 //=================================================================================
612 GEOMGUI_DimensionProperty::GEOMGUI_DimensionProperty( const QString& theProperty )
614 QRegExp aRegExpItemGroups( PATTERN_ITEM_GROUP );
615 QRegExp aRegExpItem( "^" + PATTERN_ITEM + "$" );
616 aRegExpItemGroups.setMinimal( true );
617 aRegExpItem.setMinimal( true );
620 while ( ( aPos = aRegExpItemGroups.indexIn( theProperty, aPos ) ) != -1 )
622 aPos += aRegExpItemGroups.matchedLength();
624 QString aStrItem = aRegExpItemGroups.cap(1);
626 if ( aRegExpItem.indexIn( aStrItem ) < 0 )
632 QString aStrName = aRegExpItem.cap( 1 );
633 QString aStrVisible = aRegExpItem.cap( 2 );
634 QString aStrType = aRegExpItem.cap( 3 );
635 QString aStrValues = aRegExpItem.cap( 4 );
638 aStrName.replace( "::", ":" );
639 bool isVisible = aStrVisible.toInt() != 0;
640 int aType = aStrType.toInt();
645 case DimensionType_Length : aRecord = RecordPtr( new Length ); break;
646 case DimensionType_Diameter : aRecord = RecordPtr( new Diameter ); break;
647 case DimensionType_Angle : aRecord = RecordPtr( new Angle ); break;
652 QRegExp aRegExpValues;
655 case DimensionType_Length : aRegExpValues = QRegExp( "^" + PATTERN_LENGTH + "$" ); break;
656 case DimensionType_Diameter : aRegExpValues = QRegExp( "^" + PATTERN_DIAMETER + "$" ); break;
657 case DimensionType_Angle : aRegExpValues = QRegExp( "^" + PATTERN_ANGLE + "$" ); break;
660 aRegExpValues.setMinimal(true);
662 if ( aRegExpValues.indexIn( aStrValues ) < 0 )
667 std::vector<double> aValues;
669 QStringList aStrListOfValues = aRegExpValues.capturedTexts();
670 QStringList::Iterator aStrListOfValuesIt = aStrListOfValues.begin();
671 ++aStrListOfValuesIt; // skip first capture
672 for ( ; aStrListOfValuesIt != aStrListOfValues.end(); ++aStrListOfValuesIt )
674 aValues.push_back( (*aStrListOfValuesIt).toDouble() );
679 aRecord->FromValues( aValueIt, aValues );
681 myVisibility.append( isVisible );
682 myNames.append( aStrName );
683 myRecords.append( aRecord );
687 //=================================================================================
688 // function : Destructor
690 //=================================================================================
691 GEOMGUI_DimensionProperty::~GEOMGUI_DimensionProperty()
695 //=================================================================================
696 // function : operator QVariant()
698 //=================================================================================
699 GEOMGUI_DimensionProperty::operator QVariant() const
702 aQVariant.setValue( *this );
706 //=================================================================================
707 // function : operator QString()
709 //=================================================================================
710 GEOMGUI_DimensionProperty::operator QString() const
714 VectorOfVisibility::ConstIterator aVisibilityIt = myVisibility.constBegin();
715 VectorOfRecords::ConstIterator aRecordIt = myRecords.constBegin();
716 VectorOfNames::ConstIterator aNameIt = myNames.constBegin();
717 for ( ; aRecordIt != myRecords.constEnd(); ++aRecordIt, ++aNameIt, ++aVisibilityIt )
719 QString aName = *aNameIt;
720 const bool& isVisible = *aVisibilityIt;
721 const RecordPtr& aRecord = *aRecordIt;
724 std::vector<double> aPacked;
725 aRecord->ToValues( aPacked );
727 // put values into pattern
728 QString aStringValues;
729 switch ( aRecord->Type() )
731 case DimensionType_Length : aStringValues = PATTERN_LENGTH; break;
732 case DimensionType_Diameter : aStringValues = PATTERN_DIAMETER; break;
733 case DimensionType_Angle : aStringValues = PATTERN_ANGLE; break;
738 aStringValues.remove("\\");
741 for ( ; it < aPacked.size(); ++it )
743 int aNextPos = aStringValues.indexOf("(.*)");
746 break; // invalid pattern
749 aStringValues.replace( aNextPos, 4, QString::number( aPacked.at(it) ) );
752 if ( it < aPacked.size() )
754 continue; // invalid pattern
757 // replace all ':' to '::' for pattern matching
758 aName.replace(":", "::");
761 QString("{ Name=") + aName +
762 QString(":") + QString("Visible=") + QString::number( isVisible ? 1 : 0 ) +
763 QString(":") + QString("Type=") + QString::number( (int) aRecord->Type() ) +
764 QString(":") + aStringValues + QString(" }") );
767 return anItems.join( ":" );
770 //=================================================================================
771 // function : operator ==
773 //=================================================================================
774 bool GEOMGUI_DimensionProperty::operator == (const GEOMGUI_DimensionProperty& theOther) const
776 if ( myVisibility.size() != theOther.myVisibility.size()
777 || myNames.size() != theOther.myNames.size()
778 || myRecords.size() != theOther.myRecords.size() )
783 for ( int it = 0; it < myRecords.size(); ++it )
785 if ( myVisibility[it] != theOther.myVisibility[it] )
790 if ( myNames[it] != theOther.myNames[it] )
795 const RecordPtr& aRecord = myRecords[it];
796 const RecordPtr& aOtherRecord = theOther.myRecords[it];
797 if ( aRecord->Type() != aOtherRecord->Type() )
802 switch ( aRecord->Type() )
804 case DimensionType_Length:
805 if ( (*aRecord->AsLength()) != (*aOtherRecord->AsLength()) )
811 case DimensionType_Diameter:
812 if ( (*aRecord->AsDiameter()) != (*aOtherRecord->AsDiameter()) )
818 case DimensionType_Angle:
819 if ( (*aRecord->AsAngle()) != (*aOtherRecord->AsAngle()) )
830 //=================================================================================
831 // function : GetNumber
833 //=================================================================================
834 int GEOMGUI_DimensionProperty::GetNumber() const
836 return myRecords.size();
839 //=================================================================================
840 // function : AddRecord
842 //=================================================================================
843 void GEOMGUI_DimensionProperty::AddRecord( const Handle(AIS_Dimension)& theIO, const gp_Ax3& theLCS )
845 RecordPtr aNewRecord;
847 int aType = TypeFromIO( theIO );
851 case DimensionType_Length :
853 #if OCC_VERSION_LARGE >= 0x070400ff
854 Handle(PrsDim_LengthDimension) aLength =
855 Handle(PrsDim_LengthDimension)::DownCast( theIO );
857 Handle(AIS_LengthDimension) aLength =
858 Handle(AIS_LengthDimension)::DownCast( theIO );
861 aNewRecord = RecordPtr( new Length() );
862 aNewRecord->AsLength()->Init( aLength, theLCS );
866 case DimensionType_Diameter :
868 Handle(AIS_DiameterDimension) aDiam =
869 Handle(AIS_DiameterDimension)::DownCast( theIO );
871 aNewRecord = RecordPtr( new Diameter() );
872 aNewRecord->AsDiameter()->Init( aDiam, theLCS );
876 case DimensionType_Angle :
878 Handle(AIS_AngleDimension) anAngle =
879 Handle(AIS_AngleDimension)::DownCast( theIO );
881 aNewRecord = RecordPtr( new Angle() );
882 aNewRecord->AsAngle()->Init( anAngle, theLCS );
886 myVisibility.append( true );
887 myNames.append( QString() );
888 myRecords.append( aNewRecord );
891 //=================================================================================
892 // function : AddRecord
894 //=================================================================================
895 void GEOMGUI_DimensionProperty::AddRecord( const RecordPtr& theRecord )
897 myVisibility.append( true );
898 myNames.append( QString() );
899 myRecords.append( theRecord );
902 //=================================================================================
903 // function : RemoveRecord
905 //=================================================================================
906 void GEOMGUI_DimensionProperty::RemoveRecord( const int theIndex )
908 myNames.remove( theIndex );
909 myVisibility.remove( theIndex );
910 myRecords.remove( theIndex );
913 //=================================================================================
916 //=================================================================================
917 void GEOMGUI_DimensionProperty::Clear()
920 myVisibility.clear();
924 //=================================================================================
925 // function : SetRecord
927 //=================================================================================
928 void GEOMGUI_DimensionProperty::SetRecord( const int theIndex,
929 const Handle(AIS_Dimension)& theIO,
930 const gp_Ax3& theLCS )
932 int aType = TypeFromIO( theIO );
934 RecordPtr& aChangeRecord = myRecords[theIndex];
938 case DimensionType_Length :
940 #if OCC_VERSION_LARGE >= 0x070400ff
941 Handle(PrsDim_LengthDimension) aLength =
942 Handle(PrsDim_LengthDimension)::DownCast( theIO );
944 Handle(AIS_LengthDimension) aLength =
945 Handle(AIS_LengthDimension)::DownCast( theIO );
948 aChangeRecord = RecordPtr( new Length() );
949 aChangeRecord->AsLength()->Init( aLength, theLCS );
953 case DimensionType_Diameter :
955 Handle(AIS_DiameterDimension) aDiam =
956 Handle(AIS_DiameterDimension)::DownCast( theIO );
958 aChangeRecord = RecordPtr( new Diameter() );
959 aChangeRecord->AsDiameter()->Init( aDiam, theLCS );
963 case DimensionType_Angle :
965 Handle(AIS_AngleDimension) anAngle =
966 Handle(AIS_AngleDimension)::DownCast( theIO );
968 aChangeRecord = RecordPtr( new Angle() );
969 aChangeRecord->AsAngle()->Init( anAngle, theLCS );
974 //=================================================================================
975 // function : SetRecord
977 //=================================================================================
978 void GEOMGUI_DimensionProperty::SetRecord( const int theIndex, const RecordPtr& theRecord )
980 myRecords[theIndex] = theRecord;
983 //=================================================================================
984 // function : GetRecord
986 //=================================================================================
987 const GEOMGUI_DimensionProperty::RecordPtr& GEOMGUI_DimensionProperty::GetRecord( const int theIndex ) const
989 return myRecords[theIndex];
992 //=================================================================================
993 // function : IsVisible
995 //=================================================================================
996 bool GEOMGUI_DimensionProperty::IsVisible( const int theIndex ) const
998 return myVisibility[theIndex];
1001 //=================================================================================
1002 // function : SetVisible
1004 //=================================================================================
1005 void GEOMGUI_DimensionProperty::SetVisible( const int theIndex, const bool theIsVisible )
1007 myVisibility[theIndex] = theIsVisible;
1010 //=================================================================================
1011 // function : GetName
1013 //=================================================================================
1014 QString GEOMGUI_DimensionProperty::GetName( const int theIndex ) const
1016 return myNames[theIndex];
1019 //=================================================================================
1020 // function : SetName
1022 //=================================================================================
1023 void GEOMGUI_DimensionProperty::SetName( const int theIndex, const QString &theName )
1025 myNames[theIndex] = theName;
1028 //=================================================================================
1029 // function : GetType
1031 //=================================================================================
1032 int GEOMGUI_DimensionProperty::GetType( const int theIndex ) const
1034 return myRecords[theIndex]->Type();
1037 //=================================================================================
1038 // function : LoadFromAttribute
1040 //=================================================================================
1041 void GEOMGUI_DimensionProperty::LoadFromAttribute( const std::string& theEntry )
1045 _PTR(SObject) aSObj = SalomeApp_Application::getStudy()->FindObjectID( theEntry );
1051 _PTR(StudyBuilder) aBuilder = SalomeApp_Application::getStudy()->NewBuilder();
1053 _PTR(GenericAttribute) aSeekAtt;
1054 _PTR(AttributeTableOfReal) aRecordsAtt;
1056 if ( !aSObj->FindAttribute( aSeekAtt, "AttributeTableOfReal" ) )
1061 aRecordsAtt = aSeekAtt;
1063 for ( int aRecordIt = 1; aRecordIt <= aRecordsAtt->GetNbColumns(); ++aRecordIt )
1065 std::vector<double> aPacked = aRecordsAtt->GetColumn( aRecordIt );
1069 QString aName( aRecordsAtt->GetColumnTitle( aRecordIt ).c_str() );
1075 bool isVisible = (bool) aPacked[it++];
1078 int aType = (int) aPacked[it++];
1082 case DimensionType_Length : aRecord = RecordPtr( new Length ); break;
1083 case DimensionType_Diameter : aRecord = RecordPtr( new Diameter ); break;
1084 case DimensionType_Angle : aRecord = RecordPtr( new Angle ); break;
1086 aRecord->FromValues(it, aPacked);
1088 myVisibility.append( isVisible );
1089 myNames.append( aName );
1090 myRecords.append( aRecord );
1094 //=================================================================================
1095 // function : SaveToAttribute
1097 //=================================================================================
1098 void GEOMGUI_DimensionProperty::SaveToAttribute( const std::string &theEntry )
1100 _PTR(SObject) aSObj = SalomeApp_Application::getStudy()->FindObjectID( theEntry );
1106 _PTR(StudyBuilder) aBuilder = SalomeApp_Application::getStudy()->NewBuilder();
1108 _PTR(AttributeTableOfReal) aRecordsAtt;
1110 aRecordsAtt = aBuilder->FindOrCreateAttribute( aSObj, "AttributeTableOfReal" );
1111 aRecordsAtt->SetNbColumns( 0 );
1113 for ( int it = 0; it < myRecords.size(); ++it )
1115 bool aVisibility = myVisibility[it];
1116 QString& aName = myNames[it];
1117 RecordPtr& aRecord = myRecords[it];
1119 std::vector<double> aPacked;
1122 aPacked.push_back( (double) aVisibility );
1125 aPacked.push_back( (double) aRecord->Type() );
1128 aRecord->ToValues( aPacked );
1130 aRecordsAtt->AddColumn( aPacked );
1131 aRecordsAtt->SetColumnTitle( it + 1, aName.toStdString() );
1135 //=================================================================================
1136 // function : TypeFromIO
1138 //=================================================================================
1139 int GEOMGUI_DimensionProperty::TypeFromIO( const Handle(AIS_Dimension)& theIO ) const
1141 #if OCC_VERSION_LARGE >= 0x070400ff
1142 if ( theIO->IsKind( STANDARD_TYPE( PrsDim_LengthDimension ) ) )
1144 if ( theIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) ) )
1147 return DimensionType_Length;
1150 if ( theIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
1152 return DimensionType_Diameter;
1155 if ( theIO->IsKind( STANDARD_TYPE( AIS_AngleDimension ) ) )
1157 return DimensionType_Angle;
1160 Standard_ProgramError::Raise( "unsupported dimension type" );