1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <HYDROData_Document.h>
20 #include <HYDROData_Application.h>
21 #include <HYDROData_Iterator.h>
22 #include <HYDROData_Tool.h>
23 #include <HYDROData_InterpolatorsFactory.h>
24 #include <HYDROData_StricklerTable.h>
25 #include <HYDROData_LandCoverMap.h>
27 #include <TDataStd_Real.hxx>
28 #include <TDataStd_Integer.hxx>
29 #include <TDataXtd_Position.hxx>
31 #include <TDF_Delta.hxx>
36 #include <QStringList>
37 #include <QTextStream>
40 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Document,MMgt_TShared)
42 #define PYTHON_DOC_NAME "hydro_doc"
44 static const int UNDO_LIMIT = 10; // number of possible undo operations in the module
46 static const int TAG_PROPS = 1; // general properties tag
47 static const int TAG_PROPS_NEW_ID = 1; // general properties: tag for storage of the new object ID
48 static const int TAG_OBJECTS = 2; // tag of the objects sub-tree
49 static const int TAG_HISTORY = 3; // tag of the history sub-tree (Root for History)
50 static const int TAG_LOCAL_CS = 4; // tag of local coordinate system information
51 static const int TAG_DEF_STRICKLER_COEFF = 5; // tag of default strickler coefficient
52 static const gp_Pnt2d DEFAULT_LOCAL_CS( 0, 0 );
56 typedef QMap<Standard_Integer, Handle(HYDROData_Entity)> MapOfOrdered;
57 typedef QMap<QString, Handle(HYDROData_Entity)> MapOfUnordered;
59 Handle(HYDROData_Document) HYDROData_Document::Document(const int theStudyID)
61 Handle(HYDROData_Document) aResult =
62 HYDROData_Application::GetApplication()->GetDocument(theStudyID);
63 if (aResult.IsNull()) {
64 aResult = new HYDROData_Document();
65 HYDROData_Application::GetApplication()->AddDocument(theStudyID, aResult);
70 Handle(HYDROData_Document) HYDROData_Document::Document(
71 const TDF_Label& theObjectLabel )
73 Handle(HYDROData_Document) aResDoc;
74 if ( theObjectLabel.IsNull() )
77 Handle(TDocStd_Document) anObjDoc;
80 anObjDoc = TDocStd_Document::Get( theObjectLabel );
86 if ( anObjDoc.IsNull() )
89 HYDROData_Application* anApp = HYDROData_Application::GetApplication();
91 DataMapOfStudyIDDocument::Iterator aMapIt( anApp->myDocuments );
92 for ( ; aMapIt.More(); aMapIt.Next() )
94 Handle(HYDROData_Document) anAppDoc = aMapIt.Value();
95 if ( anAppDoc.IsNull() || anAppDoc->myDoc != anObjDoc )
105 bool HYDROData_Document::HasDocument(const int theStudyID)
107 Handle(HYDROData_Document) aResult =
108 HYDROData_Application::GetApplication()->GetDocument(theStudyID);
109 return !aResult.IsNull();
112 bool HYDROData_Document::DocumentId(const Handle(HYDROData_Document)& theDocument,
115 return HYDROData_Application::GetApplication()->GetDocumentId(theDocument, theDocId);
118 Data_DocError HYDROData_Document::Load(const char* theFileName, const int theStudyID)
120 Handle(TDocStd_Document) aResult;
121 TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
122 PCDM_ReaderStatus aStatus = (PCDM_ReaderStatus) -1;
125 aStatus = HYDROData_Application::GetApplication()->Open (aPath, aResult);
127 catch (Standard_Failure)
129 if (!aResult.IsNull()) {
130 aResult->SetUndoLimit(UNDO_LIMIT);
131 HYDROData_Application::GetApplication()->AddDocument(theStudyID, new HYDROData_Document(aResult));
134 Data_DocError anError;
137 anError = DocError_OK;
139 case PCDM_RS_NoDriver:
140 case PCDM_RS_UnknownFileDriver:
141 case PCDM_RS_NoSchema:
142 case PCDM_RS_DriverFailure:
143 case PCDM_RS_WrongResource:
144 anError = DocError_ResourcesProblem;
146 case PCDM_RS_OpenError:
147 case PCDM_RS_NoDocument:
148 case PCDM_RS_WrongStreamMode:
149 case PCDM_RS_PermissionDenied:
150 anError = DocError_CanNotOpen;
152 case PCDM_RS_NoVersion:
153 anError = DocError_InvalidVersion;
155 case PCDM_RS_ExtensionFailure:
156 case PCDM_RS_FormatFailure:
157 case PCDM_RS_TypeFailure:
158 case PCDM_RS_TypeNotFoundInSchema:
159 case PCDM_RS_UnrecognizedFileFormat:
160 anError = DocError_InvalidFormat;
162 case PCDM_RS_MakeFailure:
164 anError = DocError_UnknownProblem;
170 Data_DocError HYDROData_Document::Save(const char* theFileName)
172 TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
173 PCDM_StoreStatus aStatus;
175 aStatus = HYDROData_Application::GetApplication()->SaveAs (myDoc, aPath);
177 catch (Standard_Failure) {}
178 myTransactionsAfterSave = 0;
179 Standard::Purge(); // Release free memory
182 Data_DocError anError;
185 anError = DocError_OK;
187 case PCDM_SS_DriverFailure:
188 anError = DocError_ResourcesProblem;
190 case PCDM_SS_WriteFailure:
191 //case PCDM_SS_DiskWritingFailure:
192 //case PCDM_SS_UserRightsFailure:
193 anError = DocError_CanNotOpen;
196 anError = DocError_UnknownProblem;
202 void HYDROData_Document::Close()
205 HYDROData_Application::GetApplication()->RemoveDocument(this);
208 double HYDROData_Document::GetDefaultStricklerCoefficient() const
211 TDF_Label aLabel = myDoc->Main().FindChild(TAG_DEF_STRICKLER_COEFF, Standard_False);
212 if ( !aLabel.IsNull() )
214 Handle(TDataStd_Real) anAttr;
215 if ( aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
216 aRes = anAttr->Get();
222 void HYDROData_Document::SetDefaultStricklerCoefficient( double theCoeff ) const
224 TDF_Label aLabel = myDoc->Main().FindChild(TAG_DEF_STRICKLER_COEFF);
225 if ( !aLabel.IsNull() )
227 Handle(TDataStd_Real) anAttr;
228 if ( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
229 aLabel.AddAttribute( anAttr = new TDataStd_Real() );
230 anAttr->Set( theCoeff );
234 bool HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
235 const bool theIsMultiFile ) const
237 // Try to open the file
238 QFile aFile( thePyScriptPath );
239 if ( !aFile.open( QIODevice::WriteOnly | QFile::Text ) )
242 MapOfTreatedObjects aTreatedObjects;
244 // Dump header for python script
245 QStringList aHeaderDump = DumpToPython( thePyScriptPath, aTreatedObjects, theIsMultiFile );
246 if ( aHeaderDump.isEmpty() )
249 HYDROData_Tool::WriteStringsToFile( aFile, aHeaderDump );
253 // Dump the local CS data to Python
255 QString aLCS = QString( "%1.SetLocalCS( %2, %3 )" ).arg( GetDocPyName() ).arg( myLX, 0, 'f', 3 ).arg( myLY, 0, 'f', 3 );
258 HYDROData_Tool::WriteStringsToFile( aFile, QStringList() << aLCS );
260 // Dump all model objects to Python script
261 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_IMAGE );
262 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_STRICKLER_TABLE );
263 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_POLYLINEXY );
264 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_BATHYMETRY );
265 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_PROFILE );
266 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_POLYLINE );
267 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_IMMERSIBLE_ZONE );
268 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_STREAM );
269 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CHANNEL );
270 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_DIGUE );
271 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_OBSTACLE );
272 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_LAND_COVER_MAP );
273 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CALCULATION );
275 // Dump code to close python fuction
276 if ( aRes && theIsMultiFile )
278 QStringList aFooterScript;
279 aFooterScript << QString( "" );
280 aFooterScript << QString( " pass" );
281 HYDROData_Tool::WriteStringsToFile( aFile, aFooterScript );
287 QString HYDROData_Document::GetDocPyName() const
289 QString aDocName = PYTHON_DOC_NAME;
293 if ( DocumentId( this, aDocId ) )
294 aDocName += "_" + QString::number( aDocId );
300 QStringList HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
301 MapOfTreatedObjects& theTreatedObjects,
302 const bool theIsMultiFile ) const
304 QString aDocName = GetDocPyName();
306 // Append document in to the map of treated objects to prevent names overlaping
307 theTreatedObjects.insert( aDocName, this );
310 if ( !DocumentId( this, aDocId ) )
313 QStringList aResScript;
315 aResScript << QString( "from HYDROPy import *" );
316 aResScript << QString( "from PyQt4.QtCore import *" );
317 aResScript << QString( "from PyQt4.QtGui import *" );
319 if ( theIsMultiFile )
321 aResScript << QString( "import salome" );
322 aResScript << QString( "" );
323 aResScript << QString( "def RebuildData( theStudy ):" );
324 aResScript << QString( " %1 = HYDROData_Document.Document( theStudy._get_StudyId() )" ).arg( aDocName );
328 aResScript << QString( "" );
329 aResScript << QString( "%1 = HYDROData_Document.Document( theStudy._get_StudyId() )" ).arg( aDocName );
335 bool HYDROData_Document::dumpPartitionToPython( QFile& theFile,
336 const QString& thePyScriptPath,
337 const bool theIsMultiFile,
338 MapOfTreatedObjects& theTreatedObjects,
339 const ObjectKind& theObjectKind ) const
341 if ( !theFile.isOpen() )
344 QTextStream anOutStream( &theFile );
348 HYDROData_Iterator anIterator( this, theObjectKind );
349 for( ; anIterator.More(); anIterator.Next() )
351 Handle(HYDROData_Entity) anObject = anIterator.Current();
352 if ( anObject.IsNull() )
355 QString anObjName = anObject->GetName();
356 if ( theTreatedObjects.contains( anObjName ) )
359 theTreatedObjects.insert( anObjName, anObject );
361 QStringList anObjDump = anObject->DumpToPython( thePyScriptPath, theTreatedObjects );
363 if ( theIsMultiFile )
365 // For multifile dump we use the function, see the document dump header
366 QStringList::iterator anIt = anObjDump.begin();
367 for ( ; anIt != anObjDump.end(); ++anIt )
368 anIt->prepend( " " );
371 HYDROData_Tool::WriteStringsToFile( theFile, anObjDump );
377 bool takeLastDigits( QString& theStr, int& aRes )
382 for ( int i = theStr.length() - 1; i >= 0; --i )
384 const QChar& aChar = theStr.at( i );
385 if ( !aChar.isDigit() )
388 anStrNum.prepend( aChar );
391 if ( anStrNum.isEmpty() )
394 theStr.remove( theStr.length() - anStrNum.length(), anStrNum.length() );
395 aRes = anStrNum.toInt();
400 bool isObjectNameLessThan( const QString& theStr1, const QString& theStr2 )
402 QString aStr1 = theStr1, aStr2 = theStr2;
404 int aNum1 = -1, aNum2 = -1;
405 if ( takeLastDigits( aStr1, aNum1 ) && takeLastDigits( aStr2, aNum2 ) )
407 if ( aStr1 == aStr2 )
408 return aNum1 < aNum2;
411 return theStr1 < theStr2;
414 HYDROData_SequenceOfObjects HYDROData_Document::GetObjectsLayerOrder(
415 const Standard_Boolean theIsAll ) const
417 HYDROData_SequenceOfObjects anOrder;
419 MapOfOrdered aMapOfOrdered;
420 MapOfUnordered aMapOfUnordered;
422 HYDROData_Iterator anIter( this );
423 for ( ; anIter.More(); anIter.Next() )
425 Handle(HYDROData_Entity) anObject = anIter.Current();
426 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
429 Standard_Integer anObjZLevel = -1;
430 if ( anObject->GetZLevel( anObjZLevel ) )
432 aMapOfOrdered.insert( anObjZLevel, anObject );
436 QString anObjName = anObject->GetName();
437 if ( anObjName.isEmpty() )
440 aMapOfUnordered.insert( anObjName, anObject );
444 MapOfOrdered::const_iterator anOrderedMapIt = aMapOfOrdered.constBegin();
445 for ( ; anOrderedMapIt != aMapOfOrdered.constEnd(); anOrderedMapIt++ )
447 const Handle(HYDROData_Entity)& anObject = anOrderedMapIt.value();
448 anOrder.Prepend( anObject );
453 QStringList aSortedNames = aMapOfUnordered.keys();
454 qSort( aSortedNames.begin(), aSortedNames.end(), isObjectNameLessThan );
456 for ( int i = 0; i < aSortedNames.length(); ++i )
458 QString anObjName = aSortedNames.value( i );
460 const Handle(HYDROData_Entity)& anObject = aMapOfUnordered.value( anObjName );
461 anOrder.Append( anObject );
468 void HYDROData_Document::SetObjectsLayerOrder( const HYDROData_SequenceOfObjects& theOrder )
470 // At first we remove previous model order
471 RemoveObjectsLayerOrder();
473 // Make new objects order
474 Standard_Integer aLevel = 0;
475 for ( int i = theOrder.Length(), n = 1; i >= n; --i )
477 const Handle(HYDROData_Entity)& anObject = theOrder.Value( i );
478 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
481 anObject->SetZLevel( aLevel++ );
485 void HYDROData_Document::Show( const Handle(HYDROData_Entity)& theObject )
487 HYDROData_SequenceOfObjects anOrder;
488 anOrder.Append( theObject );
492 void HYDROData_Document::Show( const HYDROData_SequenceOfObjects& theObjects )
494 MapOfUnordered aMapOfUnordered;
496 for ( int i = 1, n = theObjects.Length(); i <= n; ++i )
498 const Handle(HYDROData_Entity)& anObject = theObjects.Value( i );
499 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
502 Standard_Integer anObjZLevel = -1;
503 if ( anObject->GetZLevel( anObjZLevel ) )
505 continue; // Skip objects that already have the z-level
509 QString anObjName = anObject->GetName();
510 if ( anObjName.isEmpty() )
513 aMapOfUnordered.insert( anObjName, anObject );
517 if ( aMapOfUnordered.isEmpty() )
518 return; // Nothing to show
520 Standard_Integer aTopId = 0;
522 HYDROData_SequenceOfObjects aModelOrder = GetObjectsLayerOrder( Standard_False );
523 if ( !aModelOrder.IsEmpty() )
525 const Handle(HYDROData_Entity)& anObject = aModelOrder.First();
526 anObject->GetZLevel( aTopId );
530 aTopId += aMapOfUnordered.size() - 1;
532 QStringList aSortedNames = aMapOfUnordered.keys();
533 qSort( aSortedNames.begin(), aSortedNames.end(), isObjectNameLessThan );
535 for ( int i = 0; i < aSortedNames.length(); ++i )
537 QString anObjName = aSortedNames.value( i );
539 const Handle(HYDROData_Entity)& anObject = aMapOfUnordered.value( anObjName );
540 anObject->SetZLevel( aTopId-- );
544 void HYDROData_Document::RemoveObjectsLayerOrder()
546 HYDROData_Iterator anIter( this );
547 for ( ; anIter.More(); anIter.Next() )
549 Handle(HYDROData_Entity) anObject = anIter.Current();
550 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
553 anObject->RemoveZLevel();
557 void HYDROData_Document::StartOperation()
562 void HYDROData_Document::CommitOperation(const TCollection_ExtendedString& theName)
564 if( !myDoc->CommitCommand() ) // it means that there were no modifications done
567 NewID(); // workaround: do something just to modify the document
568 myDoc->CommitCommand();
570 myTransactionsAfterSave++;
572 if( theName.Length() != 0 )
574 const TDF_DeltaList& aList = GetUndos();
575 if( !aList.IsEmpty() )
577 Handle(TDF_Delta) aDelta = aList.Last();
578 if( !aDelta.IsNull() )
579 aDelta->SetName( theName );
584 void HYDROData_Document::AbortOperation()
586 myDoc->AbortCommand();
589 bool HYDROData_Document::IsOperation()
591 return myDoc->HasOpenCommand() != 0;
594 bool HYDROData_Document::IsModified()
596 return myTransactionsAfterSave != 0;
599 bool HYDROData_Document::CanUndo()
601 return myDoc->GetAvailableUndos() > 0;
604 const TDF_DeltaList& HYDROData_Document::GetUndos()
606 return myDoc->GetUndos();
609 void HYDROData_Document::ClearUndos()
611 return myDoc->ClearUndos();
614 void HYDROData_Document::Undo()
617 myTransactionsAfterSave--;
620 bool HYDROData_Document::CanRedo()
622 return myDoc->GetAvailableRedos() > 0;
625 const TDF_DeltaList& HYDROData_Document::GetRedos()
627 return myDoc->GetRedos();
630 void HYDROData_Document::ClearRedos()
632 return myDoc->ClearRedos();
635 void HYDROData_Document::Redo()
638 myTransactionsAfterSave++;
641 Handle(HYDROData_Entity) HYDROData_Document::CreateObject( const ObjectKind theKind )
643 return HYDROData_Iterator::CreateObject( this, theKind );
646 Handle(HYDROData_Entity) HYDROData_Document::FindObjectByName(
647 const QString& theName,
648 const ObjectKind theObjectKind ) const
650 Handle(HYDROData_Entity) anObject;
651 if ( theName.isEmpty() )
654 QStringList aNamesList;
655 aNamesList << theName;
657 HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( aNamesList, theObjectKind );
658 if( aSeqOfObjs.IsEmpty() )
661 anObject = aSeqOfObjs.First();
665 HYDROData_SequenceOfObjects HYDROData_Document::FindObjectsByNames(
666 const QStringList& theNames,
667 const ObjectKind theObjectKind ) const
669 HYDROData_SequenceOfObjects aResSeq;
671 QStringList aNamesList = theNames;
673 HYDROData_Iterator anIter( this, theObjectKind );
674 for( ; anIter.More(); anIter.Next() )
676 Handle(HYDROData_Entity) anObject = anIter.Current();
677 if( anObject.IsNull() )
680 QString anObjName = anObject->GetName();
681 if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
684 aResSeq.Append( anObject );
686 aNamesList.removeAll( anObjName );
687 if ( aNamesList.isEmpty() )
694 HYDROData_Document::HYDROData_Document()
696 HYDROData_Application::GetApplication()->NewDocument("BinOcaf", myDoc);
697 myDoc->SetUndoLimit(UNDO_LIMIT);
698 NewID(); // needed to have at least one attribute in initial document to avoid errors
699 myTransactionsAfterSave = 0;
703 myInterpolatorsFactory = 0;
706 HYDROData_Document::HYDROData_Document(const Handle(TDocStd_Document)& theDoc)
709 myTransactionsAfterSave = 0;
713 myInterpolatorsFactory = 0;
716 HYDROData_Document::~HYDROData_Document()
720 int HYDROData_Document::NewID()
722 TDF_Label anIDLab = myDoc->Main().FindChild(TAG_PROPS).
723 FindChild(TAG_PROPS_NEW_ID);
724 Handle(TDataStd_Integer) anInt;
725 if (!anIDLab.FindAttribute(TDataStd_Integer::GetID(), anInt)) {
726 anInt = TDataStd_Integer::Set(anIDLab, 0);
728 // just increment value and return
729 anInt->Set(anInt->Get() + 1);
733 TDF_Label HYDROData_Document::LabelOfObjects()
735 return myDoc->Main().FindChild(TAG_OBJECTS);
738 TDF_Label HYDROData_Document::LabelOfLocalCS() const
740 return myDoc->Main().FindChild(TAG_LOCAL_CS);
743 void HYDROData_Document::GetLocalCS( double& theLX, double& theLY ) const
745 TDF_Label aLocalCSLab = LabelOfLocalCS();
747 Handle( TDataXtd_Position ) aLocalCS;
748 if( aLocalCSLab.FindAttribute( TDataXtd_Position::GetID(), aLocalCS ) )
750 gp_Pnt aLocalCS3d = aLocalCS->GetPosition();
751 theLX = aLocalCS3d.X();
752 theLY = aLocalCS3d.Y();
756 theLX = DEFAULT_LOCAL_CS.X();
757 theLY = DEFAULT_LOCAL_CS.Y();
761 void HYDROData_Document::SetLocalCS( double theLX, double theLY )
765 // update the local CS data in attribute
766 TDF_Label aLocalCSLab = LabelOfLocalCS();
767 Handle( TDataXtd_Position ) aLocalCS;
768 if( !aLocalCSLab.FindAttribute( TDataXtd_Position::GetID(), aLocalCS ) )
769 aLocalCS = TDataXtd_Position::Set( aLocalCSLab );
771 gp_Pnt aLocalCS3d( theLX, theLY, 0 );
772 aLocalCS->SetPosition( aLocalCS3d );
774 // calculate delta for coordinates
775 double aDX = myLX - theLX;
776 double aDY = myLY - theLY;
778 // update the local CS data in internal fields
782 //update all objects in the document
783 HYDROData_Iterator anIterator( this, KIND_UNKNOWN );
784 for( ; anIterator.More(); anIterator.Next() )
785 anIterator.Current()->UpdateLocalCS( aDX, aDY );
788 void HYDROData_Document::UpdateLCSFields() const
790 if( myLX >= 0 && myLY >= 0 )
794 GetLocalCS( aLX, aLY );
795 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
800 void HYDROData_Document::Transform( double& X, double& Y, bool IsToLocalCS ) const
815 void HYDROData_Document::Transform( gp_Pnt& thePnt, bool IsToLocalCS ) const
817 double X = thePnt.X();
818 double Y = thePnt.Y();
819 double Z = thePnt.Z();
820 Transform( X, Y, IsToLocalCS );
821 thePnt = gp_Pnt( X, Y, Z );
824 void HYDROData_Document::Transform( gp_XYZ& thePnt, bool IsToLocalCS ) const
826 double X = thePnt.X();
827 double Y = thePnt.Y();
828 double Z = thePnt.Z();
829 Transform( X, Y, IsToLocalCS );
830 thePnt = gp_XYZ( X, Y, Z );
833 void HYDROData_Document::Transform( double& X, double& Y, double& Z, bool IsToLocalCS ) const
835 Transform( X, Y, IsToLocalCS );
838 void HYDROData_Document::Transform( gp_XY& thePnt, bool IsToLocalCS ) const
840 double X = thePnt.X();
841 double Y = thePnt.Y();
842 Transform( X, Y, IsToLocalCS );
843 thePnt = gp_XY( X, Y );
846 HYDROData_InterpolatorsFactory* HYDROData_Document::GetInterpolatorsFactory()
848 if ( !myInterpolatorsFactory ) {
849 myInterpolatorsFactory = new HYDROData_InterpolatorsFactory();
852 return myInterpolatorsFactory;
855 HYDROData_IProfilesInterpolator* HYDROData_Document::GetInterpolator( const TCollection_AsciiString& theName ) const
857 HYDROData_IProfilesInterpolator* anInterpolator = NULL;
859 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
860 HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
862 anInterpolator = aFactory->GetInterpolator( theName );
865 return anInterpolator;
868 NCollection_Sequence<TCollection_AsciiString> HYDROData_Document::GetInterpolatorNames() const
870 NCollection_Sequence<TCollection_AsciiString> aNames;
872 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
873 HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
875 aNames = aFactory->GetInterpolatorNames();
881 QColor HYDROData_Document::GetAssociatedColor( const QString& theStricklerType, const Handle(HYDROData_StricklerTable)& theTable ) const
883 if( !theTable.IsNull() && theTable->HasType( theStricklerType ) )
884 return theTable->GetColor( theStricklerType );
886 HYDROData_Iterator anIt( this, KIND_STRICKLER_TABLE );
887 for( ; anIt.More(); anIt.Next() )
889 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
890 if( aTable->HasType( theStricklerType ) )
891 return aTable->GetColor( theStricklerType );
896 void HYDROData_Document::CollectQGISValues( const QString& theAttrName,
897 QStringList& theAttrValues,
898 QStringList& theStricklerTypes ) const
900 HYDROData_Iterator It( this, KIND_STRICKLER_TABLE );
901 for( ; It.More(); It.Next() )
903 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
904 if( !aTable.IsNull() && aTable->GetAttrName()==theAttrName )
906 theAttrValues.clear();
907 theStricklerTypes = aTable->GetTypes();
908 foreach( QString aType, theStricklerTypes )
910 QString anAttrValue = aTable->GetAttrValue( aType );
911 theAttrValues.append( anAttrValue );