1 // Copyright (C) 2007-2013 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.
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 //=================================================================================
36 // function : Length::Init
38 //=================================================================================
39 void GEOMGUI_DimensionProperty::Length::Init( const Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS )
42 aFromLCS.SetTransformation( gp_Ax3(), theLCS );
44 FirstPoint = theIO->FirstPoint().Transformed( aFromLCS );
45 SecondPoint = theIO->SecondPoint().Transformed( aFromLCS );
46 Plane = theIO->GetPlane().Transformed( aFromLCS );
47 Flyout = theIO->GetFlyout();
48 TextHPos = theIO->DimensionAspect()->TextHorizontalPosition();
49 TextVPos = theIO->DimensionAspect()->TextVerticalPosition();
50 ArrowPos = theIO->DimensionAspect()->ArrowOrientation();
53 //=================================================================================
54 // function : Length::Update
56 //=================================================================================
57 void GEOMGUI_DimensionProperty::Length::Update( Handle(AIS_LengthDimension)& theIO, const gp_Ax3& theLCS )
60 aToLCS.SetTransformation( theLCS, gp_Ax3() );
62 gp_Pnt aPoint1 = FirstPoint.Transformed( aToLCS );
63 gp_Pnt aPoint2 = SecondPoint.Transformed( aToLCS );
64 gp_Pln aPlane = Plane.Transformed( aToLCS );
66 theIO->SetMeasuredGeometry( aPoint1, aPoint2, aPlane );
67 theIO->SetFlyout( Flyout );
69 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
70 aStyle->SetTextHorizontalPosition( TextHPos );
71 aStyle->SetTextVerticalPosition( TextVPos );
72 aStyle->SetArrowOrientation( ArrowPos );
73 theIO->SetDimensionAspect( aStyle );
76 //=================================================================================
77 // function : Length::operator ==
79 //=================================================================================
80 bool GEOMGUI_DimensionProperty::Length::operator == (const Length& theOther) const
82 if ( FirstPoint.X() != theOther.FirstPoint.X()
83 || FirstPoint.Y() != theOther.FirstPoint.Y()
84 || FirstPoint.Z() != theOther.FirstPoint.Z()
85 || SecondPoint.X() != theOther.SecondPoint.X()
86 || SecondPoint.Y() != theOther.SecondPoint.Y()
87 || SecondPoint.Z() != theOther.SecondPoint.Z() )
92 if ( Plane.Location().X() != theOther.Plane.Location().X()
93 || Plane.Location().Y() != theOther.Plane.Location().Y()
94 || Plane.Location().Z() != theOther.Plane.Location().Z()
95 || Plane.Axis().Direction().X() != theOther.Plane.Axis().Direction().X()
96 || Plane.Axis().Direction().Y() != theOther.Plane.Axis().Direction().Y()
97 || Plane.Axis().Direction().Z() != theOther.Plane.Axis().Direction().Z() )
102 if ( Flyout != theOther.Flyout
103 || TextHPos != theOther.TextHPos
104 || TextVPos != theOther.TextVPos
105 || ArrowPos != theOther.ArrowPos )
113 //=================================================================================
114 // function : Diameter::Init
116 //=================================================================================
117 void GEOMGUI_DimensionProperty::Diameter::Init( const Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS )
120 aFromLCS.SetTransformation( gp_Ax3(), theLCS );
122 Circle = theIO->Circle().Transformed( aFromLCS );
123 Plane = theIO->GetPlane().Transformed( aFromLCS );
124 Flyout = theIO->GetFlyout();
125 TextHPos = theIO->DimensionAspect()->TextHorizontalPosition();
126 TextVPos = theIO->DimensionAspect()->TextVerticalPosition();
127 ArrowPos = theIO->DimensionAspect()->ArrowOrientation();
130 //=================================================================================
131 // function : Diameter::Update
133 //=================================================================================
134 void GEOMGUI_DimensionProperty::Diameter::Update( Handle(AIS_DiameterDimension)& theIO, const gp_Ax3& theLCS )
137 aToLCS.SetTransformation( theLCS, gp_Ax3() );
139 gp_Circ aCircle = Circle.Transformed( aToLCS );
140 gp_Pln aPlane = Plane.Transformed( aToLCS );
142 Standard_Boolean isParallel =
143 aCircle.Axis().Direction().IsParallel( aPlane.Axis().Direction(), Precision::Angular() );
147 theIO->UnsetCustomPlane();
148 theIO->SetMeasuredGeometry( aCircle );
152 theIO->SetCustomPlane( aPlane );
153 theIO->SetMeasuredGeometry( aCircle );
156 theIO->SetFlyout( Flyout );
158 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
159 aStyle->SetTextHorizontalPosition( TextHPos );
160 aStyle->SetTextVerticalPosition( TextVPos );
161 aStyle->SetArrowOrientation( ArrowPos );
162 theIO->SetDimensionAspect( aStyle );
165 //=================================================================================
166 // function : Diameter::operator ==
168 //=================================================================================
169 bool GEOMGUI_DimensionProperty::Diameter::operator == (const Diameter& theOther) const
171 if ( Circle.Location().X() != theOther.Circle.Location().X()
172 || Circle.Location().Y() != theOther.Circle.Location().Y()
173 || Circle.Location().Z() != theOther.Circle.Location().Z()
174 || Circle.Axis().Direction().X() != theOther.Circle.Axis().Direction().X()
175 || Circle.Axis().Direction().Y() != theOther.Circle.Axis().Direction().Y()
176 || Circle.Axis().Direction().Z() != theOther.Circle.Axis().Direction().Z()
177 || Circle.XAxis().Direction().X() != theOther.Circle.XAxis().Direction().X()
178 || Circle.XAxis().Direction().Y() != theOther.Circle.XAxis().Direction().Y()
179 || Circle.XAxis().Direction().Z() != theOther.Circle.XAxis().Direction().Z()
180 || Circle.Radius() != theOther.Circle.Radius() )
185 if ( Plane.Location().X() != theOther.Plane.Location().X()
186 || Plane.Location().Y() != theOther.Plane.Location().Y()
187 || Plane.Location().Z() != theOther.Plane.Location().Z()
188 || Plane.Axis().Direction().X() != theOther.Plane.Axis().Direction().X()
189 || Plane.Axis().Direction().Y() != theOther.Plane.Axis().Direction().Y()
190 || Plane.Axis().Direction().Z() != theOther.Plane.Axis().Direction().Z() )
195 if ( Flyout != theOther.Flyout
196 || TextHPos != theOther.TextHPos
197 || TextVPos != theOther.TextVPos
198 || ArrowPos != theOther.ArrowPos )
206 //=================================================================================
207 // function : Angle::Init
209 //=================================================================================
210 void GEOMGUI_DimensionProperty::Angle::Init( const Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS )
213 aFromLCS.SetTransformation( gp_Ax3(), theLCS );
215 FirstPoint = theIO->FirstPoint().Transformed( aFromLCS );
216 SecondPoint = theIO->SecondPoint().Transformed( aFromLCS );
217 CenterPoint = theIO->CenterPoint().Transformed( aFromLCS );
218 Flyout = theIO->GetFlyout();
219 TextHPos = theIO->DimensionAspect()->TextHorizontalPosition();
220 TextVPos = theIO->DimensionAspect()->TextVerticalPosition();
221 ArrowPos = theIO->DimensionAspect()->ArrowOrientation();
224 //=================================================================================
225 // function : Angle::Update
227 //=================================================================================
228 void GEOMGUI_DimensionProperty::Angle::Update( Handle(AIS_AngleDimension)& theIO, const gp_Ax3& theLCS )
231 aToLCS.SetTransformation( theLCS, gp_Ax3() );
233 gp_Pnt aPoint1 = FirstPoint.Transformed( aToLCS );
234 gp_Pnt aPoint2 = CenterPoint.Transformed( aToLCS );
235 gp_Pnt aPoint3 = SecondPoint.Transformed( aToLCS );
237 theIO->SetMeasuredGeometry( aPoint1, aPoint2, aPoint3 );
238 theIO->SetFlyout( Flyout );
240 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
241 aStyle->SetTextHorizontalPosition( TextHPos );
242 aStyle->SetTextVerticalPosition( TextVPos );
243 aStyle->SetArrowOrientation( ArrowPos );
244 theIO->SetDimensionAspect( aStyle );
247 //=================================================================================
248 // function : Angle::operator ==
250 //=================================================================================
251 bool GEOMGUI_DimensionProperty::Angle::operator == (const Angle& theOther) const
253 if ( FirstPoint.X() != theOther.FirstPoint.X()
254 || FirstPoint.Y() != theOther.FirstPoint.Y()
255 || FirstPoint.Z() != theOther.FirstPoint.Z()
256 || SecondPoint.X() != theOther.SecondPoint.X()
257 || SecondPoint.Y() != theOther.SecondPoint.Y()
258 || SecondPoint.Z() != theOther.SecondPoint.Z()
259 || CenterPoint.X() != theOther.CenterPoint.X()
260 || CenterPoint.Y() != theOther.CenterPoint.Y()
261 || CenterPoint.Z() != theOther.CenterPoint.Z() )
266 if ( Flyout != theOther.Flyout
267 || TextHPos != theOther.TextHPos
268 || TextVPos != theOther.TextVPos
269 || ArrowPos != theOther.ArrowPos )
277 //=================================================================================
278 // function : Constructor
280 //=================================================================================
281 GEOMGUI_DimensionProperty::GEOMGUI_DimensionProperty()
285 //=================================================================================
286 // function : Copy constructor
288 //=================================================================================
289 GEOMGUI_DimensionProperty::GEOMGUI_DimensionProperty( const GEOMGUI_DimensionProperty& theOther )
291 const VectorOfVisibility& aOtherVis = theOther.myVisibility;
292 const VectorOfNames& aOtherNames = theOther.myNames;
293 const VectorOfRecords& aOtherRecords = theOther.myRecords;
295 VectorOfVisibility::const_iterator aVisIt = aOtherVis.constBegin();
296 VectorOfNames::const_iterator aNamesIt = aOtherNames.constBegin();
297 VectorOfRecords::const_iterator aRecordIt = aOtherRecords.constBegin();
298 for ( ; aRecordIt != aOtherRecords.constEnd(); ++aVisIt, ++aNamesIt, ++aRecordIt )
300 RecordPtr aNewRecord;
301 const RecordPtr& aRecord = *aRecordIt;
302 switch( aRecord->Type() )
304 case DimensionType_Length :
305 aNewRecord = RecordPtr( new Length( *aRecord->AsLength() ) );
308 case DimensionType_Diameter :
309 aNewRecord = RecordPtr( new Diameter( *aRecord->AsDiameter() ) );
312 case DimensionType_Angle :
313 aNewRecord = RecordPtr( new Angle( *aRecord->AsAngle() ) );
317 myVisibility.append( *aVisIt );
318 myNames.append( *aNamesIt );
319 myRecords.append( aNewRecord );
323 //=================================================================================
324 // function : Init constructor
326 //=================================================================================
327 GEOMGUI_DimensionProperty::GEOMGUI_DimensionProperty( SalomeApp_Study* theStudy, const std::string& theEntry )
329 LoadFromAttribute( theStudy, theEntry );
332 //=================================================================================
333 // function : Destructor
335 //=================================================================================
336 GEOMGUI_DimensionProperty::~GEOMGUI_DimensionProperty()
340 //=================================================================================
341 // function : operator QVariant()
343 //=================================================================================
344 GEOMGUI_DimensionProperty::operator QVariant()
347 aQVariant.setValue( *this );
351 //=================================================================================
352 // function : operator ==
354 //=================================================================================
355 bool GEOMGUI_DimensionProperty::operator == (const GEOMGUI_DimensionProperty& theOther) const
357 if ( myVisibility.size() != theOther.myVisibility.size()
358 || myNames.size() != theOther.myNames.size()
359 || myRecords.size() != theOther.myRecords.size() )
364 for ( int it = 0; it < myRecords.size(); ++it )
366 if ( myVisibility[it] != theOther.myVisibility[it] )
371 if ( myNames[it] != theOther.myNames[it] )
376 const RecordPtr& aRecord = myRecords[it];
377 const RecordPtr& aOtherRecord = theOther.myRecords[it];
378 if ( aRecord->Type() != aOtherRecord->Type() )
383 switch ( aRecord->Type() )
385 case DimensionType_Length:
386 if ( (*aRecord->AsLength()) != (*aOtherRecord->AsLength()) )
392 case DimensionType_Diameter:
393 if ( (*aRecord->AsDiameter()) != (*aOtherRecord->AsDiameter()) )
399 case DimensionType_Angle:
400 if ( (*aRecord->AsAngle()) != (*aOtherRecord->AsAngle()) )
411 //=================================================================================
412 // function : GetNumber
414 //=================================================================================
415 int GEOMGUI_DimensionProperty::GetNumber() const
417 return myRecords.size();
420 //=================================================================================
421 // function : AddRecord
423 //=================================================================================
424 void GEOMGUI_DimensionProperty::AddRecord( const Handle(AIS_Dimension)& theIO, const gp_Ax3& theLCS )
426 RecordPtr aNewRecord;
428 int aType = TypeFromIO( theIO );
432 case DimensionType_Length :
434 Handle(AIS_LengthDimension) aLength =
435 Handle(AIS_LengthDimension)::DownCast( theIO );
437 aNewRecord = RecordPtr( new Length() );
438 aNewRecord->AsLength()->Init( aLength, theLCS );
442 case DimensionType_Diameter :
444 Handle(AIS_DiameterDimension) aDiam =
445 Handle(AIS_DiameterDimension)::DownCast( theIO );
447 aNewRecord = RecordPtr( new Diameter() );
448 aNewRecord->AsDiameter()->Init( aDiam, theLCS );
452 case DimensionType_Angle :
454 Handle(AIS_AngleDimension) anAngle =
455 Handle(AIS_AngleDimension)::DownCast( theIO );
457 aNewRecord = RecordPtr( new Angle() );
458 aNewRecord->AsAngle()->Init( anAngle, theLCS );
462 myVisibility.append( true );
463 myNames.append( QString() );
464 myRecords.append( aNewRecord );
467 //=================================================================================
468 // function : AddRecord
470 //=================================================================================
471 void GEOMGUI_DimensionProperty::AddRecord( const RecordPtr& theRecord )
473 myVisibility.append( true );
474 myNames.append( QString() );
475 myRecords.append( theRecord );
478 //=================================================================================
479 // function : RemoveRecord
481 //=================================================================================
482 void GEOMGUI_DimensionProperty::RemoveRecord( const int theIndex )
484 myNames.remove( theIndex );
485 myVisibility.remove( theIndex );
486 myRecords.remove( theIndex );
489 //=================================================================================
492 //=================================================================================
493 void GEOMGUI_DimensionProperty::Clear()
496 myVisibility.clear();
500 //=================================================================================
501 // function : SetRecord
503 //=================================================================================
504 void GEOMGUI_DimensionProperty::SetRecord( const int theIndex,
505 const Handle(AIS_Dimension)& theIO,
506 const gp_Ax3& theLCS )
508 int aType = TypeFromIO( theIO );
510 RecordPtr& aChangeRecord = myRecords[theIndex];
514 case DimensionType_Length :
516 Handle(AIS_LengthDimension) aLength =
517 Handle(AIS_LengthDimension)::DownCast( theIO );
519 aChangeRecord = RecordPtr( new Length() );
520 aChangeRecord->AsLength()->Init( aLength, theLCS );
524 case DimensionType_Diameter :
526 Handle(AIS_DiameterDimension) aDiam =
527 Handle(AIS_DiameterDimension)::DownCast( theIO );
529 aChangeRecord = RecordPtr( new Diameter() );
530 aChangeRecord->AsDiameter()->Init( aDiam, theLCS );
534 case DimensionType_Angle :
536 Handle(AIS_AngleDimension) anAngle =
537 Handle(AIS_AngleDimension)::DownCast( theIO );
539 aChangeRecord = RecordPtr( new Angle() );
540 aChangeRecord->AsAngle()->Init( anAngle, theLCS );
545 //=================================================================================
546 // function : SetRecord
548 //=================================================================================
549 void GEOMGUI_DimensionProperty::SetRecord( const int theIndex, const RecordPtr& theRecord )
551 myRecords[theIndex] = theRecord;
554 //=================================================================================
555 // function : GetRecord
557 //=================================================================================
558 const GEOMGUI_DimensionProperty::RecordPtr& GEOMGUI_DimensionProperty::GetRecord( const int theIndex ) const
560 return myRecords[theIndex];
563 //=================================================================================
564 // function : IsVisible
566 //=================================================================================
567 bool GEOMGUI_DimensionProperty::IsVisible( const int theIndex ) const
569 return myVisibility[theIndex];
572 //=================================================================================
573 // function : SetVisible
575 //=================================================================================
576 void GEOMGUI_DimensionProperty::SetVisible( const int theIndex, const bool theIsVisible )
578 myVisibility[theIndex] = theIsVisible;
581 //=================================================================================
582 // function : GetName
584 //=================================================================================
585 QString GEOMGUI_DimensionProperty::GetName( const int theIndex ) const
587 return myNames[theIndex];
590 //=================================================================================
591 // function : SetName
593 //=================================================================================
594 void GEOMGUI_DimensionProperty::SetName( const int theIndex, const QString &theName )
596 myNames[theIndex] = theName;
599 //=================================================================================
600 // function : GetType
602 //=================================================================================
603 int GEOMGUI_DimensionProperty::GetType( const int theIndex ) const
605 return myRecords[theIndex]->Type();
608 //=================================================================================
609 // function : LoadFromAttribute
611 //=================================================================================
612 void GEOMGUI_DimensionProperty::LoadFromAttribute( SalomeApp_Study* theStudy,
613 const std::string& theEntry )
617 _PTR(SObject) aSObj = theStudy->studyDS()->FindObjectID( theEntry );
623 _PTR(StudyBuilder) aBuilder = theStudy->studyDS()->NewBuilder();
625 _PTR(GenericAttribute) aSeekAtt;
626 _PTR(AttributeTableOfReal) aRecordsAtt;
628 if ( !aSObj->FindAttribute( aSeekAtt, "AttributeTableOfReal" ) )
633 aRecordsAtt = aSeekAtt;
635 for ( int aRecordIt = 1; aRecordIt <= aRecordsAtt->GetNbColumns(); ++aRecordIt )
637 std::vector<double> aPacked = aRecordsAtt->GetColumn( aRecordIt );
641 QString aName( aRecordsAtt->GetColumnTitle( aRecordIt ).c_str() );
647 bool isVisible = (bool) aPacked[it++];
650 int aType = (int) aPacked[it++];
654 case DimensionType_Length :
656 Length* aLength = new Length;
658 // custom plane [2,3,4,5]
659 Standard_Real A = (Standard_Real) aPacked[it++];
660 Standard_Real B = (Standard_Real) aPacked[it++];
661 Standard_Real C = (Standard_Real) aPacked[it++];
662 Standard_Real D = (Standard_Real) aPacked[it++];
663 aLength->Plane = gp_Pln( A, B, C, D );
666 aLength->Flyout = (Standard_Real) aPacked[it++];
669 aLength->TextHPos = (Prs3d_DimensionTextHorizontalPosition)(int)aPacked[it++];
670 aLength->TextVPos = (Prs3d_DimensionTextVerticalPosition) (int)aPacked[it++];
673 aLength->ArrowPos = (Prs3d_DimensionArrowOrientation) (int)aPacked[it++];
675 // point 1 [10,11,12]
676 Standard_Real aFirstX = aPacked[it++];
677 Standard_Real aFirstY = aPacked[it++];
678 Standard_Real aFirstZ = aPacked[it++];
679 aLength->FirstPoint = gp_Pnt( aFirstX, aFirstY, aFirstZ );
681 // point 2 [13,14,15]
682 Standard_Real aSecondX = aPacked[it++];
683 Standard_Real aSecondY = aPacked[it++];
684 Standard_Real aSecondZ = aPacked[it++];
685 aLength->SecondPoint = gp_Pnt( aSecondX, aSecondY, aSecondZ );
687 aRecord = RecordPtr( aLength );
691 case DimensionType_Diameter :
693 Diameter* aDiam = new Diameter;
695 // custom plane [2,3,4,5]
696 Standard_Real A = (Standard_Real) aPacked[it++];
697 Standard_Real B = (Standard_Real) aPacked[it++];
698 Standard_Real C = (Standard_Real) aPacked[it++];
699 Standard_Real D = (Standard_Real) aPacked[it++];
700 aDiam->Plane = gp_Pln( A, B, C, D );
703 aDiam->Flyout = (Standard_Real) aPacked[it++];
706 aDiam->TextHPos = (Prs3d_DimensionTextHorizontalPosition)(int)aPacked[it++];
707 aDiam->TextVPos = (Prs3d_DimensionTextVerticalPosition) (int)aPacked[it++];
710 aDiam->ArrowPos = (Prs3d_DimensionArrowOrientation) (int)aPacked[it++];
712 // circle location [10,11,12]
713 Standard_Real aLocX = (Standard_Real) aPacked[it++];
714 Standard_Real aLocY = (Standard_Real) aPacked[it++];
715 Standard_Real aLocZ = (Standard_Real) aPacked[it++];
717 // circle normal [13,14,15]
718 Standard_Real aNormX = (Standard_Real) aPacked[it++];
719 Standard_Real aNormY = (Standard_Real) aPacked[it++];
720 Standard_Real aNormZ = (Standard_Real) aPacked[it++];
722 // x-direction [16,17,18]
723 Standard_Real aXDirX = (Standard_Real) aPacked[it++];
724 Standard_Real aXDirY = (Standard_Real) aPacked[it++];
725 Standard_Real aXDirZ = (Standard_Real) aPacked[it++];
728 Standard_Real aRadius = (Standard_Real) aPacked[it++];
730 gp_Ax2 anAx( gp_Pnt( aLocX, aLocY, aLocZ ),
731 gp_Dir( aNormX, aNormY, aNormZ ),
732 gp_Dir( aXDirX, aXDirY, aXDirZ ) );
734 aDiam->Circle = gp_Circ( anAx, aRadius );
736 aRecord = RecordPtr( aDiam );
740 case DimensionType_Angle :
742 Angle* anAngle = new Angle;
745 anAngle->Flyout = (Standard_Real) aPacked[it++];
748 anAngle->TextHPos = (Prs3d_DimensionTextHorizontalPosition)(int)aPacked[it++];
749 anAngle->TextVPos = (Prs3d_DimensionTextVerticalPosition) (int)aPacked[it++];
752 anAngle->ArrowPos = (Prs3d_DimensionArrowOrientation) (int)aPacked[it++];
755 Standard_Real aFirstX = (Standard_Real) aPacked[it++];
756 Standard_Real aFirstY = (Standard_Real) aPacked[it++];
757 Standard_Real aFirstZ = (Standard_Real) aPacked[it++];
760 Standard_Real aSecondX = (Standard_Real) aPacked[it++];
761 Standard_Real aSecondY = (Standard_Real) aPacked[it++];
762 Standard_Real aSecondZ = (Standard_Real) aPacked[it++];
765 Standard_Real aCenterX = (Standard_Real) aPacked[it++];
766 Standard_Real aCenterY = (Standard_Real) aPacked[it++];
767 Standard_Real aCenterZ = (Standard_Real) aPacked[it++];
769 anAngle->FirstPoint = gp_Pnt( aFirstX, aFirstY, aFirstZ );
770 anAngle->SecondPoint = gp_Pnt( aSecondX, aSecondY, aSecondZ );
771 anAngle->CenterPoint = gp_Pnt( aCenterX, aCenterY, aCenterZ );
773 aRecord = RecordPtr( anAngle );
778 myVisibility.append( isVisible );
779 myNames.append( aName );
780 myRecords.append( aRecord );
784 //=================================================================================
785 // function : SaveToAttribute
787 //=================================================================================
788 void GEOMGUI_DimensionProperty::SaveToAttribute( SalomeApp_Study *theStudy,
789 const std::string &theEntry )
791 _PTR(SObject) aSObj = theStudy->studyDS()->FindObjectID( theEntry );
797 _PTR(StudyBuilder) aBuilder = theStudy->studyDS()->NewBuilder();
799 _PTR(AttributeTableOfReal) aRecordsAtt;
801 aRecordsAtt = aBuilder->FindOrCreateAttribute( aSObj, "AttributeTableOfReal" );
802 aRecordsAtt->SetNbColumns( 0 );
804 for ( int it = 0; it < myRecords.size(); ++it )
806 bool aVisibility = myVisibility[it];
807 QString& aName = myNames[it];
808 RecordPtr& aRecord = myRecords[it];
810 std::vector<double> aPacked;
813 aPacked.push_back( (double) aVisibility );
816 aPacked.push_back( (double) aRecord->Type() );
818 switch ( aRecord->Type() )
820 case DimensionType_Length:
822 Length* aProps = aRecord->AsLength();
824 // custom plane [2,3,4,5]
825 Standard_Real A, B, C, D;
826 aProps->Plane.Coefficients( A, B, C, D );
827 aPacked.push_back( (double) A );
828 aPacked.push_back( (double) B );
829 aPacked.push_back( (double) C );
830 aPacked.push_back( (double) D );
833 aPacked.push_back( (double) aProps->Flyout );
836 aPacked.push_back( (double) aProps->TextHPos );
837 aPacked.push_back( (double) aProps->TextVPos );
840 aPacked.push_back( (double) aProps->ArrowPos );
842 // point 1 [10,11,12]
843 aPacked.push_back( (double) aProps->FirstPoint.X() );
844 aPacked.push_back( (double) aProps->FirstPoint.Y() );
845 aPacked.push_back( (double) aProps->FirstPoint.Z() );
847 // point 2 [13,14,15]
848 aPacked.push_back( (double) aProps->SecondPoint.X() );
849 aPacked.push_back( (double) aProps->SecondPoint.Y() );
850 aPacked.push_back( (double) aProps->SecondPoint.Z() );
854 case DimensionType_Diameter:
856 Diameter* aProps = aRecord->AsDiameter();
858 // custom plane [2,3,4,5]
859 Standard_Real A, B, C, D;
860 aProps->Plane.Coefficients( A, B, C, D );
861 aPacked.push_back( (double) A );
862 aPacked.push_back( (double) B );
863 aPacked.push_back( (double) C );
864 aPacked.push_back( (double) D );
867 aPacked.push_back( (double) aProps->Flyout );
870 aPacked.push_back( (double) aProps->TextHPos );
871 aPacked.push_back( (double) aProps->TextVPos );
874 aPacked.push_back( (double) aProps->ArrowPos );
876 // circle location [10,11,12]
877 aPacked.push_back( (double) aProps->Circle.Location().X() );
878 aPacked.push_back( (double) aProps->Circle.Location().Y() );
879 aPacked.push_back( (double) aProps->Circle.Location().Z() );
881 // circle normal [13,14,15]
882 aPacked.push_back( (double) aProps->Circle.Axis().Direction().X() );
883 aPacked.push_back( (double) aProps->Circle.Axis().Direction().Y() );
884 aPacked.push_back( (double) aProps->Circle.Axis().Direction().Z() );
886 // x-direction [16,17,18]
887 aPacked.push_back( (double) aProps->Circle.XAxis().Direction().X() );
888 aPacked.push_back( (double) aProps->Circle.XAxis().Direction().Y() );
889 aPacked.push_back( (double) aProps->Circle.XAxis().Direction().Z() );
892 aPacked.push_back( (double) aProps->Circle.Radius() );
896 case DimensionType_Angle:
898 Angle* aProps = aRecord->AsAngle();
901 aPacked.push_back( (double) aProps->Flyout );
904 aPacked.push_back( (double) aProps->TextHPos );
905 aPacked.push_back( (double) aProps->TextVPos );
908 aPacked.push_back( (double) aProps->ArrowPos );
911 aPacked.push_back( (double) aProps->FirstPoint.X() );
912 aPacked.push_back( (double) aProps->FirstPoint.Y() );
913 aPacked.push_back( (double) aProps->FirstPoint.Z() );
916 aPacked.push_back( (double) aProps->SecondPoint.X() );
917 aPacked.push_back( (double) aProps->SecondPoint.Y() );
918 aPacked.push_back( (double) aProps->SecondPoint.Z() );
921 aPacked.push_back( (double) aProps->CenterPoint.X() );
922 aPacked.push_back( (double) aProps->CenterPoint.Y() );
923 aPacked.push_back( (double) aProps->CenterPoint.Z() );
928 aRecordsAtt->AddColumn( aPacked );
929 aRecordsAtt->SetColumnTitle( it + 1, aName.toStdString() );
933 //=================================================================================
934 // function : TypeFromIO
936 //=================================================================================
937 int GEOMGUI_DimensionProperty::TypeFromIO( const Handle(AIS_Dimension)& theIO ) const
939 if ( theIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) ) )
941 return DimensionType_Length;
944 if ( theIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
946 return DimensionType_Diameter;
949 if ( theIO->IsKind( STANDARD_TYPE( AIS_AngleDimension ) ) )
951 return DimensionType_Angle;
954 Standard_ProgramError::Raise( "unsupported dimension type" );