HYDROGUI_CopyPastePositionOp.h
HYDROGUI_DataBrowser.h
HYDROGUI_DataModel.h
+ HYDROGUI_DataModelSync.h
HYDROGUI_DataObject.h
HYDROGUI_DeleteDlg.h
HYDROGUI_DeleteOp.h
HYDROGUI_CopyPastePositionOp.cxx
HYDROGUI_DataBrowser.cxx
HYDROGUI_DataModel.cxx
+ HYDROGUI_DataModelSync.cxx
HYDROGUI_DataObject.cxx
HYDROGUI_DeleteDlg.cxx
HYDROGUI_DeleteOp.cxx
#include <HYDROData_Bathymetry.h>
#include <HYDROData_CalculationCase.h>
+#include <HYDROGUI_DataModelSync.h>
#include <HYDROData_Document.h>
#include <HYDROData_DummyObject3D.h>
#include <HYDROData_Image.h>
#include <SUIT_ResourceMgr.h>
#include <SUIT_Study.h>
#include <SUIT_Tools.h>
+#include <SUIT_TreeSync.h>
#include <HYDROData_Document.h>
if( !aStudyRoot )
return;
- // create root object if not exist
- CAM_DataObject* aRootObj = root();
- if( !aRootObj )
- aRootObj = createRootModuleObject( aStudyRoot );
-
- if( !aRootObj )
- return;
-
- DataObjectList aList;
- aRootObj->children( aList );
- QListIterator<SUIT_DataObject*> anIter( aList );
- while( anIter.hasNext() )
- removeChild( aRootObj, anIter.next() );
+ // create a new root object
+ CAM_DataObject* aNewRootObj = new CAM_DataObject();
Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theStudyId );
if( aDocument.IsNull() )
// Create root objects:
// IMAGES
- LightApp_DataObject* anImageRootObj = createObject( aRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
+ LightApp_DataObject* anImageRootObj = createObject( aNewRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
// BATHYMETRY
- LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
+ LightApp_DataObject* aBathymetryRootObj = createObject( aNewRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
// ARTIFICIAL OBJECTS
- LightApp_DataObject* anArtificialObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) );
+ LightApp_DataObject* anArtificialObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) );
// NATURAL OBJECTS
- LightApp_DataObject* aNaturalObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
+ LightApp_DataObject* aNaturalObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
// OBSTACLES
- LightApp_DataObject* anObstaclesRootObj = createObject( aRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
+ LightApp_DataObject* anObstaclesRootObj = createObject( aNewRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
// CALCULATION CASES
- LightApp_DataObject* aCalculRootObj = createObject( aRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
+ LightApp_DataObject* aCalculRootObj = createObject( aNewRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
// POLYLINES
- LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) );
+ LightApp_DataObject* aPolylineRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) );
// POLYLINES
- LightApp_DataObject* aPolyline3DRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) );
+ LightApp_DataObject* aPolyline3DRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) );
// PROFILES
- LightApp_DataObject* aProfileRootObj = createObject( aRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
+ LightApp_DataObject* aProfileRootObj = createObject( aNewRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
// VISUAL STATES
- LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
+ LightApp_DataObject* aVisualStateRootObj = createObject( aNewRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN );
for( ; anIterator.More(); anIterator.Next() ) {
}
}
- if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
- {
- anObjectBrowser->setAutoOpenLevel( 3 );
- anObjectBrowser->openLevels();
- }
+ //if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
+ //{
+ // anObjectBrowser->setAutoOpenLevel( 3 );
+ // anObjectBrowser->openLevels();
+ //}
+
+ HYDROGUI_DataModelSync aSync( aNewRootObj );
+ SUIT_DataObject* aRoot = root();
+ if( !aRoot )
+ aRoot = createRootModuleObject( aStudyRoot );
+ ::synchronize < suitPtr, suitPtr, HYDROGUI_DataModelSync >
+ ( aNewRootObj, aRoot, aSync );
}
HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject )
--- /dev/null
+
+#include <HYDROGUI_DataModelSync.h>
+#include <HYDROGUI_DataObject.h>
+
+HYDROGUI_DataModelSync::HYDROGUI_DataModelSync( SUIT_DataObject* theRoot )
+ : myRoot( theRoot )
+{
+}
+
+HYDROGUI_DataModelSync::~HYDROGUI_DataModelSync()
+{
+}
+
+void HYDROGUI_DataModelSync::deleteItemWithChildren( const suitPtr& theSuitPtr ) const
+{
+ if( !theSuitPtr )
+ return;
+
+ DataObjectList aChildren;
+ theSuitPtr->children( aChildren );
+ foreach( SUIT_DataObject* anObj, aChildren )
+ deleteItemWithChildren( anObj );
+
+ delete theSuitPtr;
+}
+
+suitPtr HYDROGUI_DataModelSync::nullSrc() const
+{
+ return 0;
+}
+
+suitPtr HYDROGUI_DataModelSync::nullTrg() const
+{
+ return 0;
+}
+
+QList<suitPtr> HYDROGUI_DataModelSync::children( const suitPtr& theSuitPtr ) const
+{
+ QList<suitPtr> aChildren;
+ if( theSuitPtr )
+ {
+ DataObjectList anObjList;
+ theSuitPtr->children( anObjList );
+ foreach( SUIT_DataObject* anObj, anObjList )
+ aChildren.append( anObj );
+ }
+ return aChildren;
+}
+
+suitPtr HYDROGUI_DataModelSync::parent( const suitPtr& theSuitPtr ) const
+{
+ return theSuitPtr ? theSuitPtr->parent() : 0;
+}
+
+void HYDROGUI_DataModelSync::updateItem( const suitPtr& theSrcPtr, const suitPtr& theTrgPtr ) const
+{
+ HYDROGUI_DataObject* aDataObj = dynamic_cast<HYDROGUI_DataObject*>( theTrgPtr );
+ if( aDataObj )
+ aDataObj->updateBy( theSrcPtr );
+
+ HYDROGUI_NamedObject* aNamedObj = dynamic_cast<HYDROGUI_NamedObject*>( theTrgPtr );
+ if( aNamedObj )
+ aNamedObj->updateBy( theSrcPtr );
+}
+
+bool HYDROGUI_DataModelSync::isEqual( const suitPtr& theSrcPtr, const suitPtr& theTrgPtr ) const
+{
+ if( theSrcPtr==myRoot )
+ return true;
+
+ if( theSrcPtr==0 )
+ return theTrgPtr==0;
+
+ if( theTrgPtr==0 )
+ return theSrcPtr==0;
+
+ QString aSrcClass = typeid( *theSrcPtr ).name();
+ QString aTrgClass = typeid( *theTrgPtr ).name();
+ return aSrcClass==aTrgClass;
+}
+
+suitPtr HYDROGUI_DataModelSync::createItem( const suitPtr& theSrcPtr,
+ const suitPtr& theParent,
+ const suitPtr& theAfter ) const
+{
+ if( theParent )
+ {
+ int aPos = theParent->childPos( theAfter );
+ if( aPos>=0 )
+ theParent->insertChild( theSrcPtr, aPos+1 );
+ else
+ theParent->appendChild( theSrcPtr );
+ }
+ return theSrcPtr;
+}
+
--- /dev/null
+
+#ifndef HYDROGUI_DATA_MODEL_SYNC_HEADER
+#define HYDROGUI_DATA_MODEL_SYNC_HEADER
+
+#include <QList>
+
+class SUIT_DataObject;
+
+typedef SUIT_DataObject* suitPtr;
+
+class HYDROGUI_DataModelSync
+{
+public:
+ HYDROGUI_DataModelSync( SUIT_DataObject* theRoot );
+ ~HYDROGUI_DataModelSync();
+
+ void deleteItemWithChildren( const suitPtr& ) const;
+ suitPtr nullSrc() const;
+ suitPtr nullTrg() const;
+ QList<suitPtr> children( const suitPtr& ) const;
+ suitPtr parent( const suitPtr& ) const;
+ void updateItem( const suitPtr&, const suitPtr& ) const;
+ bool isEqual( const suitPtr&, const suitPtr& ) const;
+ suitPtr createItem( const suitPtr&, const suitPtr&, const suitPtr& ) const;
+
+private:
+ SUIT_DataObject* myRoot;
+};
+
+#endif
return aRes;
}
+void HYDROGUI_DataObject::updateBy( SUIT_DataObject* theObj )
+{
+ HYDROGUI_DataObject* aDataObj = dynamic_cast<HYDROGUI_DataObject*>( theObj );
+ if( !aDataObj )
+ return;
+
+ myData = aDataObj->myData;
+ myParentEntry = aDataObj->myParentEntry;
+ myIsValid = aDataObj->myIsValid;
+ myIsInOperation = aDataObj->myIsInOperation;
+ myIcon = aDataObj->myIcon;
+}
+
+
+
+
HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
return aFont;
}
+void HYDROGUI_NamedObject::updateBy( SUIT_DataObject* theObj )
+{
+ HYDROGUI_NamedObject* aNamedObj = dynamic_cast<HYDROGUI_NamedObject*>( theObj );
+ if( !aNamedObj )
+ return;
+
+ myName = aNamedObj->myName;
+ myParentEntry = aNamedObj->myParentEntry;
+ myIcon = aNamedObj->myIcon;
+ myIsInOperation = aNamedObj->myIsInOperation;
+}
+
+
+
+
+
+
HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
const QString& theName,
const QString& theParentEntry,
*/
bool isInOperation() const { return myIsInOperation; }
+ void updateBy( SUIT_DataObject* );
+
protected:
Handle(HYDROData_Entity) myData; ///< object from data model
QString myParentEntry;
*/
bool isInOperation() const { return myIsInOperation; }
+ void updateBy( SUIT_DataObject* );
+
private:
QString myName; ///< name in the OB
QString myParentEntry;