2) Moving Presentation classes from GraphicsView to HYDROGUI.
3) Raw development.
#include <HYDROData.h>
+#include <NCollection_Sequence.hxx>
#include <TDF_Label.hxx>
#include <QString>
*/
HYDRODATA_EXPORT void CopyTo(Handle_HYDROData_Object theDestination) const;
+ /**
+ * Returns the label of this object.
+ */
+ HYDRODATA_EXPORT TDF_Label& Label() {return myLab;}
+
protected:
friend class HYDROData_Iterator;
*/
HYDRODATA_EXPORT virtual void SetLabel(TDF_Label theLabel);
- /**
- * Returns the label of this object.
- */
- TDF_Label& Label() {return myLab;}
-
/**
* Internal method that used to store the byte array attribute
* \param theTag tag of a label to store attribute (for 0 this is myLab)
TDF_Label myLab; ///< label of this object
};
+typedef NCollection_Sequence<Handle_HYDROData_Object> HYDROData_SequenceOfObjects;
+
///! Is Equal for HYDROData_Object mapping
HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2);
HYDROGUI_ColorWidget.h
HYDROGUI_DataModel.h
HYDROGUI_DataObject.h
+ HYDROGUI_Displayer.h
+ HYDROGUI_GVSelector.h
HYDROGUI_ImportImageDlg.h
HYDROGUI_ImportImageOp.h
HYDROGUI_InputPanel.h
HYDROGUI_ObjSelector.h
HYDROGUI_Operation.h
HYDROGUI_Operations.h
+ HYDROGUI_Prs.h
+ HYDROGUI_PrsDriver.h
+ HYDROGUI_PrsImage.h
+ HYDROGUI_PrsImageDriver.h
+ HYDROGUI_PrsImageFrame.h
+ HYDROGUI_Tool.h
HYDROGUI_TwoImagesDlg.h
HYDROGUI_TwoImagesOp.h
+ HYDROGUI_UpdateFlags.h
)
QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS})
HYDROGUI_ColorWidget.cxx
HYDROGUI_DataModel.cxx
HYDROGUI_DataObject.cxx
+ HYDROGUI_Displayer.cxx
+ HYDROGUI_GVSelector.cxx
HYDROGUI_ImportImageDlg.cxx
HYDROGUI_ImportImageOp.cxx
HYDROGUI_InputPanel.cxx
HYDROGUI_Operation.cxx
HYDROGUI_Operations.cxx
HYDROGUI_TwoImagesDlg.cxx
+ HYDROGUI_Prs.cxx
+ HYDROGUI_PrsDriver.cxx
+ HYDROGUI_PrsImage.cxx
+ HYDROGUI_PrsImageDriver.cxx
+ HYDROGUI_PrsImageFrame.cxx
+ HYDROGUI_Tool.cxx
HYDROGUI_TwoImagesOp.cxx
)
bool HYDROGUI_DataModel::save( QStringList& theFileList )
{
- if (!module()->application()->activeStudy())
+ if( !module()->application()->activeStudy() )
return false;
const int aStudyId = module()->application()->activeStudy()->id();
bool HYDROGUI_DataModel::isModified() const
{
- int aStudyID = module()->application()->activeStudy()->id();
- return HYDROData_Document::Document( aStudyID )->IsModified();
+ int aStudyId = module()->application()->activeStudy()->id();
+ return HYDROData_Document::Document( aStudyId )->IsModified();
}
bool HYDROGUI_DataModel::isSaved() const
SUIT_DataObject* HYDROGUI_DataModel::findObject( const QString& theEntry ) const
{
- SUIT_DataObject* anObject = HYDROGUI_DataObject::objectByEntry( theEntry );
- if( !anObject )
- {
- LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
- anObject = anApp ? anApp->findObject( theEntry ) : 0;
- }
- return anObject;
+ LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
+ return anApp ? anApp->findObject( theEntry ) : 0;
}
void HYDROGUI_DataModel::update( LightApp_DataObject* theObject,
update( aModule->getStudyId() );
}
+Handle(HYDROData_Object) HYDROGUI_DataModel::objectByEntry( const QString& theEntry,
+ const ObjectKind theObjectKind )
+{
+ const int aStudyId = module()->application()->activeStudy()->id();
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
+ if( !aDocument.IsNull() )
+ {
+ HYDROData_Iterator anIterator( aDocument, theObjectKind );
+ for( ; anIterator.More(); anIterator.Next() )
+ {
+ Handle(HYDROData_Object) anObject = anIterator.Current();
+ if( !anObject.IsNull() )
+ {
+ QString anEntry = HYDROGUI_DataObject::dataObjectEntry( anObject );
+ if( anEntry == theEntry )
+ return anObject;
+ }
+ }
+ }
+ return NULL;
+}
+
LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent,
Handle(HYDROData_Object) theModelObject )
{
#ifndef HYDROGUI_DATAMODEL_H
#define HYDROGUI_DATAMODEL_H
-#include "HYDROGUI.h"
-
#include <HYDROData_Object.h>
#include <QMap>
class SUIT_DataObject;
class HYDROGUI_DataObject;
-/*!
+/**
* \class HYDROGUI_DataModel
* \brief The class representing the HYDROGUI data model
*/
class HYDROGUI_DataModel : public LightApp_DataModel, public SUIT_DataSearcher
{
public:
- /**
- * Constructor.
- * \param theModule module object
- */
+ /**
+ * Constructor.
+ * \param theModule module object
+ */
HYDROGUI_DataModel( CAM_Module* theModule );
virtual ~HYDROGUI_DataModel();
/**
* Open the document into the data model. Reimplemented.
- * /param theURL opened study path
- * /param theStudy object study
- * /param theFileList list of opened files for this model.
+ * \param theURL opened study path
+ * \param theStudy object study
+ * \param theFileList list of opened files for this model.
*/
virtual bool open( const QString& theURL,
CAM_Study* theStudy,
/**
* Saves the document. Reimplemented.
- * /param returned theFileList list of saved files of this model.
+ * \param returned theFileList list of saved files of this model.
*/
virtual bool save( QStringList& theFileList );
/**
* Saves as the document. Reimplemented.
- * /param theURL saved study path
- * /param theStudy object study
- * /param returned theFileList list of saved files of this model.
+ * \param theURL saved study path
+ * \param theStudy object study
+ * \param returned theFileList list of saved files of this model.
*/
virtual bool saveAs( const QString& theURL,
CAM_Study* theStudy,
/**
* Returns modification status. Reimplemented.
- * /return boolean value of modification status
+ * \return boolean value of modification status
*/
virtual bool isModified() const;
/**
* Updates the internal structure of data object tree starting from specified data object \a obj.
- * /param theObject start data object
- * /param theStudy study object
+ * \param theObject start data object
+ * \param theStudy study object
*/
virtual void update( LightApp_DataObject* theObject = 0,
LightApp_Study* theStudy = 0 );
*/
void updateModel();
+ /**
+ * Find a data object by the specified entry and kind
+ */
+ Handle(HYDROData_Object) objectByEntry( const QString& theEntry,
+ const ObjectKind theObjectKind );
+
protected:
/**
* Creates the GUI data object according to the model object.
#include <SUIT_DataObject.h>
+#include <TDF_Tool.hxx>
+
HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent,
Handle(HYDROData_Object) theData )
: CAM_DataObject( theParent ),
LightApp_DataObject( theParent ),
myData( theData )
{
- // unique identifier generated from pointer to this object, like: "HD_0x123457"
- // "H" means "HYDRO", "D" means "data" to avoid conflicts with named objects
- std::ostringstream aStream;
- aStream << "HD_" << this;
- myEntry = QString( aStream.str().c_str() );
}
QString HYDROGUI_DataObject::entry() const
{
- return myEntry;
+ return HYDROGUI_DataObject::dataObjectEntry( modelObject() );
}
QString HYDROGUI_DataObject::name() const
return QString();
}
-HYDROGUI_DataObject* HYDROGUI_DataObject::objectByEntry( const QString& theEntry )
+QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Object)& theObject )
{
- static const QString aPrefixD( "HD_" );
- if ( theEntry.indexOf( aPrefixD ) != 0 )
- return NULL; // not HYDRO entry
-
- std::istringstream aStream( theEntry.toLatin1().constData() + 3 ); // start reading just after "HD_"
- void* aPtr = 0;
- aStream >> aPtr;
-
- return ( HYDROGUI_DataObject* )aPtr;
+ QString aEntryStr = QString::null;
+ if( !theObject.IsNull() )
+ {
+ TCollection_AsciiString aLabEntr;
+ TDF_Tool::Entry( theObject->Label(), aLabEntr );
+ aEntryStr = HYDROGUI_DataObject::entryPrefix() + QString( aLabEntr.ToCString() );
+ }
+ return aEntryStr;
}
HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
QString HYDROGUI_NamedObject::entry() const
{
- // unique identifier generated from pointer to this object, like: "HD_0x123457"
- // "H" means "HYDRO", "N" means "named" to avoid conflicts with data objects
- return "HN_" + myName;
+ return LightApp_DataObject::entry();
}
QString HYDROGUI_NamedObject::name() const
{
return myName;
}
-
-QString HYDROGUI_NamedObject::nameByEntry( const QString& theEntry )
-{
- static const QString aPrefixN( "HN_" );
- if( theEntry.indexOf( aPrefixN ) != 0 )
- return QString(); // not HYDRO entry
-
- return theEntry.right( 3 );
-}
#ifndef HYDROGUI_DATAOBJECT_H
#define HYDROGUI_DATAOBJECT_H
-#include "HYDROGUI.h"
-
#include <HYDROData_Object.h>
#include <LightApp_DataObject.h>
void setObject( Handle(HYDROData_Object) theObject ) { myData = theObject; }
/**
- * Returns \a HYDROGUI_DataObject by the entry string of this object.
- * \returns NULL if this is not HYDRO entry, or cannot cast to HYDROGUI_DataObject
+ * Returns the entry prefix for all HYDRO data objects.
+ */
+ static QString entryPrefix() { return QString( "HYDRO_" ); }
+
+ /**
+ * Returns the full entry for the specified data object.
*/
- static HYDROGUI_DataObject* objectByEntry( const QString& theEntry );
+ static QString dataObjectEntry( const Handle(HYDROData_Object)& theObject );
protected:
Handle(HYDROData_Object) myData; ///< object from data model
- QString myEntry; ///< optimization: store generated entry to return it quickly
- int myStudyId; ///< the study identifier: check an object validity in the corresponded document
};
/**
*/
virtual QString name() const;
- /**
- * Returns name of the named object that is identified by this entry.
- * \param theEntry entry of the object (used for selection identification).
- * \returns name of the object, or empty string if it is not HYDRO named object
- */
- static QString nameByEntry( const QString& theEntry );
-
private:
QString myName; ///< name in the OB
};
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_Displayer.h"
+
+#include "HYDROGUI_DataModel.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_Prs.h"
+#include "HYDROGUI_PrsImageDriver.h"
+#include "HYDROGUI_Tool.h"
+
+#include <GraphicsView_Viewer.h>
+#include <GraphicsView_ViewPort.h>
+
+HYDROGUI_Displayer::HYDROGUI_Displayer( HYDROGUI_Module* theModule )
+: myModule( theModule )
+{
+}
+
+HYDROGUI_Displayer::~HYDROGUI_Displayer()
+{
+}
+
+void HYDROGUI_Displayer::SetToUpdate( const HYDROData_SequenceOfObjects& theObjs,
+ const int theViewerId )
+{
+ GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
+ if( !aViewer )
+ return;
+
+ GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
+ if( !aViewPort )
+ return;
+
+ GraphicsView_ObjectList anObjectList = aViewPort->getObjects();
+ for( int i = 1, n = theObjs.Length(); i <= n; i++ )
+ {
+ Handle(HYDROData_Object) anObj = theObjs.Value( i );
+ if( anObj.IsNull() )
+ continue;
+
+ if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList ) )
+ aPrs->setIsToUpdate( true );
+ }
+}
+
+void HYDROGUI_Displayer::UpdateAll( const int theViewerId,
+ const bool theIsInit,
+ const bool theIsForced )
+{
+ if( theIsInit )
+ EraseAll( theViewerId );
+ DisplayAll( theViewerId, theIsForced );
+}
+
+void HYDROGUI_Displayer::EraseAll( const int theViewerId )
+{
+ GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
+ if( !aViewer )
+ return;
+
+ GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
+ if( !aViewPort )
+ return;
+
+ GraphicsView_ObjectListIterator anIter( aViewPort->getObjects() );
+ while( anIter.hasNext() )
+ {
+ if( GraphicsView_Object* anObject = anIter.next() )
+ {
+ aViewPort->removeItem( anObject );
+ delete anObject;
+ }
+ }
+}
+
+void HYDROGUI_Displayer::DisplayAll( const int theViewerId,
+ const bool theIsForced )
+{
+ HYDROGUI_DataModel* aModel = (HYDROGUI_DataModel*)myModule->dataModel();
+ if( aModel )
+ {
+ HYDROData_SequenceOfObjects aSeq;
+ HYDROGUI_Tool::GetPrsSubObjects( aModel, theViewerId, aSeq );
+ Update( aSeq, theViewerId, theIsForced );
+ }
+}
+
+void HYDROGUI_Displayer::Update( const HYDROData_SequenceOfObjects& theObjs,
+ const int theViewerId,
+ const bool theIsForced )
+{
+ // First of all, kill all bad presentations
+ purgeObjects( theViewerId );
+
+ // Now dig in the data model
+ HYDROData_SequenceOfObjects anObjectsToErase, anObjectsToDisplay;
+
+ for( int i = 1, n = theObjs.Length(); i <= n; i++ )
+ {
+ const Handle(HYDROData_Object)& anObj = theObjs.Value( i );
+ if( anObj.IsNull() )
+ anObjectsToErase.Append( anObj );
+ else
+ anObjectsToDisplay.Append( anObj );
+ }
+
+ if( anObjectsToErase.Length() )
+ Erase( anObjectsToErase, theViewerId );
+ if( anObjectsToDisplay.Length() )
+ Display( anObjectsToDisplay, theViewerId, theIsForced );
+}
+
+void HYDROGUI_Displayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
+ const int theViewerId )
+{
+ GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
+ if( !aViewer )
+ return;
+
+ GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
+ if( !aViewPort )
+ return;
+
+ HYDROGUI_DataModel* aModel = (HYDROGUI_DataModel*)myModule->dataModel();
+ if( aModel )
+ {
+ GraphicsView_ObjectList anObjectList = aViewPort->getObjects();
+ for( int i = 1, n = theObjs.Length(); i <= n; i++ )
+ {
+ // the object may be null or dead
+ const Handle(HYDROData_Object)& anObj = theObjs.Value( i );
+ if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList ) )
+ {
+ aViewPort->removeItem( aPrs );
+ delete aPrs;
+ }
+ }
+ }
+}
+
+void HYDROGUI_Displayer::Display( const HYDROData_SequenceOfObjects& theObjs,
+ const int theViewerId,
+ const bool theIsForced )
+{
+ GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
+ if( !aViewer )
+ return;
+
+ GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
+ if( !aViewPort )
+ return;
+
+ bool anIsDisplayed = false;
+ GraphicsView_ObjectList anObjectList = aViewPort->getObjects();
+ for( int i = 1, n = theObjs.Length(); i <= n; i++ )
+ {
+ Handle(HYDROData_Object) anObj = theObjs.Value( i );
+ if( anObj.IsNull() )
+ continue;
+
+ HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList );
+
+ bool anIsInserted = ( aPrs != 0 );
+ if( !aPrs || aPrs->getIsToUpdate() || theIsForced )
+ {
+ if( HYDROGUI_PrsDriver* aDriver = getDriver( anObj ) )
+ {
+ if( aDriver->Update( anObj, aPrs ) && aPrs && !anIsInserted )
+ aViewPort->addItem( aPrs );
+ }
+ }
+
+ if( aPrs )
+ {
+ bool isVisible = true; // anObj->IsVisible()
+ aPrs->setVisible( true );
+ }
+ }
+
+ aViewPort->fitAll();
+}
+
+void HYDROGUI_Displayer::purgeObjects( const int theViewerId )
+{
+ GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
+ if( !aViewer )
+ return;
+
+ GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
+ if( !aViewPort )
+ return;
+
+ GraphicsView_ObjectListIterator anIter( aViewPort->getObjects() );
+ while( anIter.hasNext() )
+ {
+ GraphicsView_Object* tmp = anIter.next();
+ if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( tmp ) )
+ {
+ Handle(HYDROData_Object) anObject = aPrs->getObject();
+ if( anObject.IsNull() )
+ {
+ aViewPort->removeItem( aPrs );
+ //delete aPrs; // ouv: to do
+ }
+ }
+ }
+}
+
+HYDROGUI_PrsDriver* HYDROGUI_Displayer::getDriver( const Handle(HYDROData_Object)& theObj )
+{
+ HYDROGUI_PrsDriver* aDriver = NULL;
+ ObjectKind aKind = theObj->GetKind();
+ PrsDriversMap::iterator anIter = myPrsDriversMap.find( aKind );
+ if( anIter != myPrsDriversMap.end() )
+ aDriver = anIter.value();
+ else
+ {
+ switch( aKind )
+ {
+ case KIND_IMAGE:
+ aDriver = new HYDROGUI_PrsImageDriver();
+ myPrsDriversMap[ aKind ] = aDriver;
+ break;
+ default:
+ break;
+ }
+ }
+ return aDriver;
+}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_DISPLAYER_H
+#define HYDROGUI_DISPLAYER_H
+
+#include <HYDROData_Object.h>
+
+#include <QMap>
+
+class HYDROGUI_Module;
+class HYDROGUI_PrsDriver;
+
+class GraphicsView_Viewer;
+
+/**
+ * \class HYDROGUI_DataModel
+ * \brief Class intended to create, display and update the presentations.
+ */
+class HYDROGUI_Displayer
+{
+public:
+ /**
+ * \brief Constructor.
+ * \param theModule module object
+ */
+ HYDROGUI_Displayer( HYDROGUI_Module* theModule );
+
+ /**
+ * \brief Destructor.
+ */
+ virtual ~HYDROGUI_Displayer();
+
+public:
+ /**
+ * \brief Force the specified objects to be updated.
+ * \param theObjs sequence of objects to update
+ * \param theViewerId viewer identifier
+ */
+ void SetToUpdate( const HYDROData_SequenceOfObjects& theObjs,
+ const int theViewerId );
+
+ /**
+ * \brief Update all objects in the viewer.
+ * \param theViewerId viewer identifier
+ * \param theIsInit flag used for initial update
+ * \param theIsForced flag used to update all objects, including the unchanged ones
+ */
+ void UpdateAll( const int theViewerId,
+ const bool theIsInit,
+ const bool theIsForced );
+
+protected:
+ /**
+ * \brief Erase all viewer objects.
+ * \param theViewerId viewer identifier
+ */
+ void EraseAll( const int theViewerId );
+
+ /**
+ * \brief Update and display all objects in the viewer.
+ * \param theViewerId viewer identifier
+ * \param theIsForced flag used to update all objects, including the unchanged ones
+ */
+ void DisplayAll( const int theViewerId,
+ const bool theIsForced );
+
+ /**
+ * \brief Update the specified viewer objects.
+ * \param theObjs sequence of objects to update
+ * \param theViewerId viewer identifier
+ * \param theIsForced flag used to update all objects, including the unchanged ones
+ */
+ void Update( const HYDROData_SequenceOfObjects& theObjs,
+ const int theViewerId,
+ const bool theIsForced );
+
+ /**
+ * \brief Erase the specified viewer objects.
+ * \param theObjs sequence of objects to erase
+ * \param theViewerId viewer identifier
+ */
+ void Erase( const HYDROData_SequenceOfObjects& theObjs,
+ const int theViewerId );
+
+ /**
+ * \brief Display the specified viewer objects.
+ * \param theObjs sequence of objects to display
+ * \param theViewerId viewer identifier
+ * \param theIsForced flag used to update all objects, including the unchanged ones
+ */
+ void Display( const HYDROData_SequenceOfObjects& theObjs,
+ const int theViewerId,
+ const bool theIsForced );
+
+private:
+ /**
+ * \brief Purge all invalid objects in the viewer.
+ * \param theViewerId viewer identifier
+ */
+ void purgeObjects( const int theViewerId );
+
+ /**
+ * \brief Get the presentation driver for the specified data object.
+ * \param theObj data object
+ */
+ HYDROGUI_PrsDriver* getDriver( const Handle(HYDROData_Object)& theObj );
+
+private:
+ HYDROGUI_Module* myModule;
+
+ typedef QMap< ObjectKind, HYDROGUI_PrsDriver* > PrsDriversMap;
+ PrsDriversMap myPrsDriversMap;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_GVSelector.h"
+
+#include "HYDROGUI_DataModel.h"
+#include "HYDROGUI_DataObject.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_Prs.h"
+#include "HYDROGUI_Tool.h"
+
+#include <GraphicsView_Object.h>
+#include <GraphicsView_Selector.h>
+#include <GraphicsView_ViewPort.h>
+#include <GraphicsView_Viewer.h>
+
+#include <LightApp_DataOwner.h>
+
+HYDROGUI_GVSelector::HYDROGUI_GVSelector( HYDROGUI_Module* theModule,
+ GraphicsView_Viewer* theViewer,
+ SUIT_SelectionMgr* theSelMgr )
+: LightApp_GVSelector( theViewer, theSelMgr ),
+ myModule( theModule )
+{
+}
+
+HYDROGUI_GVSelector::~HYDROGUI_GVSelector()
+{
+}
+
+void HYDROGUI_GVSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const
+{
+ if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
+ {
+ for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() )
+ {
+ if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( aViewPort->selectedObject() ) )
+ {
+ QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aPrs->getObject() );
+ theList.append( new LightApp_DataOwner( anEntry ) );
+ }
+ }
+ }
+}
+
+void HYDROGUI_GVSelector::setSelection( const SUIT_DataOwnerPtrList& theList )
+{
+ HYDROGUI_DataModel* aModel = myModule->getDataModel();
+ if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() )
+ {
+ aViewPort->clearSelected();
+ SUIT_DataOwnerPtrList::const_iterator it;
+ GraphicsView_ObjectList anObjectList = aViewPort->getObjects();
+ for ( it = theList.begin(); it != theList.end(); ++it )
+ {
+ LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( (*it).operator->() );
+ if ( anOwner )
+ {
+ QString anEntry = anOwner->entry();
+ Handle(HYDROData_Object) aModelObject = aModel->objectByEntry( anEntry, KIND_IMAGE );
+ if( !aModelObject.IsNull() )
+ {
+ if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( aModelObject, anObjectList ) )
+ aViewPort->setSelected( aPrs );
+ }
+ }
+ }
+ }
+}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_GVSELECTOR_H
+#define HYDROGUI_GVSELECTOR_H
+
+#include <LightApp_GVSelector.h>
+
+class HYDROGUI_Module;
+
+class HYDROGUI_GVSelector : public LightApp_GVSelector
+{
+ Q_OBJECT
+
+public:
+ HYDROGUI_GVSelector( HYDROGUI_Module*,
+ GraphicsView_Viewer*,
+ SUIT_SelectionMgr* );
+ virtual ~HYDROGUI_GVSelector();
+
+protected:
+ virtual void getSelection( SUIT_DataOwnerPtrList& ) const;
+ virtual void setSelection( const SUIT_DataOwnerPtrList& );
+
+private:
+ HYDROGUI_Module* myModule;
+};
+
+#endif
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_ImportImageDlg.h"
+
+#include "HYDROGUI_PrsImage.h"
+
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+
+#include <QDoubleValidator>
+#include <QFileDialog>
+#include <QGroupBox>
+#include <QLabel>
+#include <QLayout>
+#include <QLineEdit>
+#include <QPainter>
+#include <QPicture>
+#include <QPushButton>
+#include <QToolButton>
+
+HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle )
+: HYDROGUI_InputPanel( theModule, theTitle )
+{
+ SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+
+ // Import image from file
+ QGroupBox* aFileGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ) );
+
+ QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), aFileGroup );
+
+ myFileName = new QLineEdit( aFileGroup );
+ myFileName->setReadOnly( true );
+
+ QToolButton* aBrowseBtn = new QToolButton( aFileGroup );
+ aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
+
+ QBoxLayout* aFileLayout = new QHBoxLayout( aFileGroup );
+ aFileLayout->setMargin( 5 );
+ aFileLayout->setSpacing( 5 );
+ aFileLayout->addWidget( aFileNameLabel );
+ aFileLayout->addWidget( myFileName );
+ aFileLayout->addWidget( aBrowseBtn );
+
+ // Mapping
+ myMappingGroup = new QGroupBox( tr( "MAPPING" ) );
+
+ QGridLayout* aMappingLayout = new QGridLayout( myMappingGroup );
+ aMappingLayout->setMargin( 5 );
+ aMappingLayout->setSpacing( 5 );
+
+ // Make a pixmap for arrow
+ QPixmap anArrowPixmap = aResMgr->loadPixmap( "HYDRO", tr( "ARROW_RIGHT_ICO" ) );
+
+ QPicture anArrowPicture;
+ anArrowPicture.setBoundingRect( QRect( QPoint( 0, 0 ), anArrowPixmap.size() ) );
+
+ QPainter aPainter;
+ aPainter.begin( &anArrowPicture );
+ aPainter.drawPixmap( 0, 0, anArrowPixmap );
+ aPainter.end();
+
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ QString aPointStr;
+ switch( aPointType )
+ {
+ case HYDROGUI_PrsImage::PointA: aPointStr = tr( "POINT_A" ); break;
+ case HYDROGUI_PrsImage::PointB: aPointStr = tr( "POINT_B" ); break;
+ case HYDROGUI_PrsImage::PointC: aPointStr = tr( "POINT_C" ); break;
+ }
+ QPushButton* aPointBtn = new QPushButton( aPointStr, myMappingGroup );
+ aPointBtn->setCheckable( true );
+
+ QLabel* aPointXLabel = new QLabel( tr( "X" ), myMappingGroup );
+ QLabel* aPointYLabel = new QLabel( tr( "Y" ), myMappingGroup );
+
+ QLineEdit* aPointX1 = new QLineEdit( myMappingGroup );
+ QLineEdit* aPointY1 = new QLineEdit( myMappingGroup );
+
+ aPointX1->setReadOnly( true );
+ aPointY1->setReadOnly( true );
+
+ //QLabel* aPointArrowLabel = new QLabel( ">", myMappingGroup );
+ QLabel* aPointArrowLabel = new QLabel( myMappingGroup );
+ aPointArrowLabel->setPicture( anArrowPicture );
+
+ QLineEdit* aPointX2 = new QLineEdit( myMappingGroup );
+ QLineEdit* aPointY2 = new QLineEdit( myMappingGroup );
+
+ QDoubleValidator* aDoubleValidator = new QDoubleValidator();
+ aPointX2->setValidator( aDoubleValidator );
+ aPointY2->setValidator( aDoubleValidator );
+
+ int aRow = 3 * aPointType;
+ aMappingLayout->addWidget( aPointBtn, aRow, 0, 2, 1 );
+ aMappingLayout->addWidget( aPointXLabel, aRow, 1 );
+ aMappingLayout->addWidget( aPointX1, aRow, 2 );
+ aMappingLayout->addWidget( aPointArrowLabel, aRow, 3, 2, 1 );
+ aMappingLayout->addWidget( aPointX2, aRow, 4 );
+ aMappingLayout->addWidget( aPointYLabel, aRow + 1, 1 );
+ aMappingLayout->addWidget( aPointY1, aRow + 1, 2 );
+ aMappingLayout->addWidget( aPointY2, aRow + 1, 4 );
+
+ if( aPointType != HYDROGUI_PrsImage::PointC )
+ {
+ QFrame* aLine = new QFrame( myMappingGroup );
+ aLine->setFrameShape( QFrame::HLine );
+ aLine->setFrameShadow( QFrame::Sunken );
+ aMappingLayout->addWidget( aLine, aRow + 2, 0, 1, 5 );
+ }
+
+ myPointBtnMap[ aPointType ] = aPointBtn;
+ myPointX1Map[ aPointType ] = aPointX1;
+ myPointY1Map[ aPointType ] = aPointY1;
+ myPointX2Map[ aPointType ] = aPointX2;
+ myPointY2Map[ aPointType ] = aPointY2;
+
+ connect( aPointBtn, SIGNAL( toggled( bool ) ), this, SLOT( onPointBtnToggled( bool ) ) );
+ }
+
+ // Common
+ addWidget( aFileGroup, 0, 0 );
+ addWidget( myMappingGroup, 1, 0 );
+
+ setRowStretch();
+
+ connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
+}
+
+HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
+{
+}
+
+void HYDROGUI_ImportImageDlg::reset()
+{
+ myFileName->clear();
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ QPushButton* aBtn = myPointBtnMap[ aPointType ];
+ bool anIsBlocked = aBtn->blockSignals( true );
+ aBtn->setChecked( false );
+ aBtn->blockSignals( anIsBlocked );
+
+ myPointX1Map[ aPointType ]->clear();
+ myPointY1Map[ aPointType ]->clear();
+ myPointX2Map[ aPointType ]->clear();
+ myPointY2Map[ aPointType ]->clear();
+ }
+ myMappingGroup->setEnabled( false );
+}
+
+void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap )
+{
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ if( theMap.contains( aPointType ) )
+ {
+ const TransformationData& aData = theMap[ aPointType ];
+ myPointX1Map[ aPointType ]->setText( QString::number( aData.first.x() ) );
+ myPointY1Map[ aPointType ]->setText( QString::number( aData.first.y() ) );
+ }
+ }
+}
+
+bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap ) const
+{
+ theMap.clear();
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ bool anIsOk = false;
+ int aX1 = myPointX1Map[ aPointType ]->text().toInt( &anIsOk );
+ if( !anIsOk )
+ return false;
+
+ anIsOk = false;
+ int aY1 = myPointY1Map[ aPointType ]->text().toInt( &anIsOk );
+ if( !anIsOk )
+ return false;
+
+ anIsOk = false;
+ double aX2 = myPointX2Map[ aPointType ]->text().toDouble( &anIsOk );
+ if( !anIsOk )
+ return false;
+
+ anIsOk = false;
+ double aY2 = myPointY2Map[ aPointType ]->text().toDouble( &anIsOk );
+ if( !anIsOk )
+ return false;
+
+ TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ) );
+ theMap[ aPointType ] = aData;
+ }
+ return true;
+}
+
+void HYDROGUI_ImportImageDlg::initializePointSelection()
+{
+ myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
+}
+
+void HYDROGUI_ImportImageDlg::synchronizeTransformedPoints()
+{
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ myPointX2Map[ aPointType ]->setText( myPointX1Map[ aPointType ]->text() );
+ myPointY2Map[ aPointType ]->setText( myPointY1Map[ aPointType ]->text() );
+ }
+}
+
+void HYDROGUI_ImportImageDlg::onBrowse()
+{
+ QString aFilter( tr( "IMAGE_FILTER" ) );
+ QString aFileName = QFileDialog::getOpenFileName( this, tr( "BROWSE_IMAGE_FILE" ), "", aFilter );
+ if( !aFileName.isEmpty() )
+ {
+ myFileName->setText( aFileName );
+ emit createPreview( aFileName );
+ myMappingGroup->setEnabled( true );
+ }
+}
+
+void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
+{
+ int aPointType = HYDROGUI_PrsImage::None;
+ if( theState )
+ {
+ QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
+ while( anIter.hasNext() )
+ {
+ int aBtnPointType = anIter.next().key();
+ QPushButton* aBtn = anIter.value();
+ if( aBtn == sender() )
+ aPointType = aBtnPointType;
+ else
+ {
+ bool anIsBlocked = aBtn->blockSignals( true );
+ aBtn->setChecked( false );
+ aBtn->blockSignals( anIsBlocked );
+ }
+ }
+ }
+ emit activatePointSelection( aPointType );
+}
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_IMPORTIMAGEDLG_H
+#define HYDROGUI_IMPORTIMAGEDLG_H
+
+#include "HYDROGUI_InputPanel.h"
+
+#include <QMap>
+
+class QGroupBox;
+class QLineEdit;
+
+class HYDROGUI_ImportImageDlg : public HYDROGUI_InputPanel
+{
+ Q_OBJECT
+
+public:
+ typedef QPair< QPoint, QPointF > TransformationData;
+ typedef QMap< int, TransformationData > TransformationDataMap;
+
+public:
+ HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle );
+ virtual ~HYDROGUI_ImportImageDlg();
+
+ void reset();
+
+ void setTransformationDataMap( const TransformationDataMap& theMap );
+ bool getTransformationDataMap( TransformationDataMap& theMap ) const;
+
+ void initializePointSelection();
+ void synchronizeTransformedPoints();
+
+protected slots:
+ void onBrowse();
+ void onPointBtnToggled( bool );
+
+signals:
+ void createPreview( QString );
+ void activatePointSelection( int );
+
+private:
+ QLineEdit* myFileName;
+
+ QGroupBox* myMappingGroup;
+ QMap<int, QPushButton*> myPointBtnMap;
+ QMap<int, QLineEdit*> myPointX1Map;
+ QMap<int, QLineEdit*> myPointY1Map;
+ QMap<int, QLineEdit*> myPointX2Map;
+ QMap<int, QLineEdit*> myPointY2Map;
+};
+
+#endif
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
-#include <HYDROGUI_ImportImageOp.h>
+#include "HYDROGUI_ImportImageOp.h"
+
+#include "HYDROGUI_ImportImageDlg.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_PrsImage.h"
+#include "HYDROGUI_Tool.h"
+
+#include <HYDROData_Document.h>
+#include <HYDROData_Image.h>
+
+#include <GraphicsView_ViewManager.h>
+#include <GraphicsView_ViewPort.h>
+#include <GraphicsView_Viewer.h>
+
+#include <LightApp_Application.h>
+#include <LightApp_UpdateFlags.h>
+
+#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule )
- : HYDROGUI_Operation( theModule )
+: HYDROGUI_Operation( theModule ),
+ myActiveViewManager( 0 ),
+ myPreviewViewManager( 0 ),
+ myPreviewPrs( 0 ),
+ myPointType( HYDROGUI_PrsImage::None )
{
}
{
}
+void HYDROGUI_ImportImageOp::startOperation()
+{
+ HYDROGUI_Operation::startOperation();
+
+ HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
+ aPanel->reset();
+}
+
HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
{
- return 0;
+ HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportImageDlg( module(), tr( "IMPORT_IMAGE" ) );
+ connect( aPanel, SIGNAL( createPreview( QString ) ),
+ this, SLOT( onCreatePreview( QString ) ) );
+ connect( aPanel, SIGNAL( activatePointSelection( int ) ),
+ this, SLOT( onActivatePointSelection( int ) ) );
+ return aPanel;
+}
+
+void HYDROGUI_ImportImageOp::OnApply()
+{
+ HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
+
+ HYDROGUI_ImportImageDlg::TransformationDataMap aMap;
+ bool anIsOk = aPanel->getTransformationDataMap( aMap );
+ if( !anIsOk || !myPreviewPrs )
+ {
+ SUIT_MessageBox::critical( module()->getApp()->desktop(),
+ tr( "INSUFFICIENT_INPUT_DATA" ),
+ tr( "INPUT_VALID_DATA" ) );
+ return;
+ }
+
+ double xa1 = aMap[ HYDROGUI_PrsImage::PointA ].first.x();
+ double ya1 = aMap[ HYDROGUI_PrsImage::PointA ].first.y();
+ double xb1 = aMap[ HYDROGUI_PrsImage::PointB ].first.x();
+ double yb1 = aMap[ HYDROGUI_PrsImage::PointB ].first.y();
+ double xc1 = aMap[ HYDROGUI_PrsImage::PointC ].first.x();
+ double yc1 = aMap[ HYDROGUI_PrsImage::PointC ].first.y();
+
+ double xa2 = aMap[ HYDROGUI_PrsImage::PointA ].second.x();
+ double ya2 = aMap[ HYDROGUI_PrsImage::PointA ].second.y();
+ double xb2 = aMap[ HYDROGUI_PrsImage::PointB ].second.x();
+ double yb2 = aMap[ HYDROGUI_PrsImage::PointB ].second.y();
+ double xc2 = aMap[ HYDROGUI_PrsImage::PointC ].second.x();
+ double yc2 = aMap[ HYDROGUI_PrsImage::PointC ].second.y();
+
+ QTransform aTransform1( xa1, ya1, 1, xb1, yb1, 1, xc1, yc1, 1 );
+ QTransform aTransform2( xa2, ya2, 1, xb2, yb2, 1, xc2, yc2, 1 );
+
+ QTransform aTransform = aTransform1.inverted() * aTransform2;
+
+ QImage anImage = myPreviewPrs->getImage();
+
+ closePreview();
+
+ int aStudyId = module()->getStudyId();
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
+ if( !aDocument.IsNull() )
+ {
+ Handle(HYDROData_Image) anImageObj =
+ Handle(HYDROData_Image)::DownCast( aDocument->CreateObject( KIND_IMAGE ) );
+ if( !anImageObj.IsNull() )
+ {
+ static int ImageId = 0;
+ anImageObj->SetName( QString( "Image_%1" ).arg( QString::number( ++ImageId ) ) );
+
+ anImageObj->SetImage( anImage );
+ anImageObj->SetTrsf( aTransform );
+
+ module()->update( UF_Model | UF_Viewer );
+ }
+ }
+ commit();
+}
+
+void HYDROGUI_ImportImageOp::OnCancel()
+{
+ closePreview();
+ abort();
+}
+
+void HYDROGUI_ImportImageOp::onCreatePreview( QString theFileName )
+{
+ LightApp_Application* anApp = module()->getApp();
+
+ myActiveViewManager = anApp->activeViewManager();
+
+ myPreviewPrs = new HYDROGUI_PrsImage( 0 ); // no data object
+
+ QImage anImage( theFileName );
+ myPreviewPrs->setImage( anImage );
+
+ myPreviewPrs->compute();
+
+ myPreviewViewManager =
+ dynamic_cast<GraphicsView_ViewManager*>( anApp->createViewManager( GraphicsView_Viewer::Type() ) );
+ if( myPreviewViewManager )
+ {
+ myPreviewViewManager->setTitle( tr( "MAPPING" ) );
+ if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
+ {
+ if( GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort() )
+ {
+ aViewPort->setMousePositionEnabled( true );
+
+ aViewPort->addItem( myPreviewPrs );
+ aViewPort->fitAll();
+
+ myPreviewPrs->setIsTransformationPointPreview( true );
+ }
+ connect( aViewer, SIGNAL( selectionChanged( GV_SelectionChangeStatus ) ),
+ this, SLOT( onPointSelected() ) );
+ }
+ }
+
+ HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
+
+ aPanel->initializePointSelection();
+ onPointSelected();
+
+ aPanel->synchronizeTransformedPoints();
+}
+
+void HYDROGUI_ImportImageOp::onActivatePointSelection( int thePointType )
+{
+ myPointType = thePointType;
+ if( myPreviewPrs )
+ myPreviewPrs->setTransformationPointMode( thePointType );
+}
+
+void HYDROGUI_ImportImageOp::onPointSelected()
+{
+ HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
+
+ const HYDROGUI_PrsImage::TransformationPointMap& aPointMap =
+ myPreviewPrs->getTransformationPointMap();
+ HYDROGUI_PrsImage::TransformationPointMapIterator anIter( aPointMap );
+ while( anIter.hasNext() )
+ {
+ int aPointType = anIter.next().key();
+ const HYDROGUI_PrsImage::TransformationPoint& aTransformationPoint = anIter.value();
+ const QPoint& aPoint = aTransformationPoint.Point;
+
+ HYDROGUI_ImportImageDlg::TransformationData aData( aPoint, QPointF() );
+ aDataMap[ aPointType ] = aData;
+ }
+
+ ( (HYDROGUI_ImportImageDlg*)inputPanel() )->setTransformationDataMap( aDataMap );
+}
+
+void HYDROGUI_ImportImageOp::closePreview()
+{
+ if( myPreviewPrs )
+ {
+ delete myPreviewPrs;
+ myPreviewPrs = 0;
+ }
+
+ if( myPreviewViewManager )
+ {
+ module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
+ myPreviewViewManager = 0;
+ }
+
+ if( myActiveViewManager )
+ HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
}
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
-#ifndef HYDROGUI_IMPORT_IMAGE_OP_HEADER
-#define HYDROGUI_IMPORT_IMAGE_OP_HEADER
+#ifndef HYDROGUI_IMPORTIMAGEOP_H
+#define HYDROGUI_IMPORTIMAGEOP_H
-#include <HYDROGUI_Operation.h>
+#include "HYDROGUI_Operation.h"
+
+class GraphicsView_ViewManager;
+
+class SUIT_ViewManager;
+
+class HYDROGUI_PrsImage;
class HYDROGUI_ImportImageOp : public HYDROGUI_Operation
{
+ Q_OBJECT
+
public:
HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule );
virtual ~HYDROGUI_ImportImageOp();
protected:
+ virtual void startOperation();
+
virtual HYDROGUI_InputPanel* createInputPanel() const;
+
+protected slots:
+ virtual void OnApply();
+ virtual void OnCancel();
+
+ void onCreatePreview( QString );
+ void onActivatePointSelection( int );
+ void onPointSelected();
+
+private:
+ void closePreview();
+
+private:
+ SUIT_ViewManager* myActiveViewManager;
+
+ GraphicsView_ViewManager* myPreviewViewManager;
+ HYDROGUI_PrsImage* myPreviewPrs;
+
+ int myPointType;
};
#endif
myMainFrame = new QFrame( this );
QGridLayout* aMainLayout = new QGridLayout( myMainFrame );
+ aMainLayout->setMargin( 0 );
+ aMainLayout->setSpacing( 5 );
+
myBtnFrame = new QFrame( this );
aLayout->addWidget( myMainFrame, 1 );
aLayout->addWidget( myBtnFrame, 0 );
aMainLayout->addWidget( theWidget, aRow, 1 );
}
+void HYDROGUI_InputPanel::addWidget( QWidget* theWidget,
+ const int theRow,
+ const int theColumn )
+{
+ QGridLayout* aMainLayout = dynamic_cast<QGridLayout*>( myMainFrame->layout() );
+ aMainLayout->addWidget( theWidget, theRow, theColumn );
+}
+
void HYDROGUI_InputPanel::addSeparator()
{
QGridLayout* aMainLayout = dynamic_cast<QGridLayout*>( myMainFrame->layout() );
#ifndef HYDROGUI_INPUTPANEL_H
#define HYDROGUI_INPUTPANEL_H
-#include "HYDROGUI.h"
#include <QDockWidget>
-class HYDROGUI_Module;
class QFrame;
class QPushButton;
+class HYDROGUI_Module;
+
/**\class HYDROGUI_Dialog
*\brief The base class representing base input panel for all HYDROGUI panels
*/
virtual ~HYDROGUI_InputPanel();
void addWidget( const QString& theLabel, QWidget* theWidget );
+ void addWidget( QWidget* theWidget, const int theRow, const int theColumn );
void addSeparator();
void setRowStretch();
#include "HYDROGUI_Module.h"
+#include "HYDROGUI.h"
#include "HYDROGUI_DataModel.h"
+#include "HYDROGUI_Displayer.h"
+#include "HYDROGUI_GVSelector.h"
#include "HYDROGUI_InputPanel.h"
#include "HYDROGUI_ObjSelector.h"
#include "HYDROGUI_Operations.h"
+#include "HYDROGUI_PrsImage.h"
+#include "HYDROGUI_UpdateFlags.h"
-#include <GraphicsView_PrsImage.h>
#include <GraphicsView_ViewFrame.h>
+#include <GraphicsView_ViewManager.h>
#include <GraphicsView_ViewPort.h>
#include <GraphicsView_Viewer.h>
#include <LightApp_Application.h>
#include <LightApp_GVSelector.h>
#include <LightApp_SelectionMgr.h>
+#include <LightApp_UpdateFlags.h>
-#include <SUIT_Desktop.h>
#include <SUIT_Study.h>
#include <SUIT_ViewManager.h>
}
HYDROGUI_Module::HYDROGUI_Module()
-: LightApp_Module( "HYDRO GUI" )
+: LightApp_Module( "HYDRO" ),
+ myDisplayer( 0 ),
+ myIsUpdateEnabled( true )
{
}
void HYDROGUI_Module::initialize( CAM_Application* theApp )
{
- printf( "Initialization of the HYDROGUI module\n" );
LightApp_Module::initialize( theApp );
CreateActions();
setMenuShown( false );
- //startOperation( ImportImageId );
- startOperation( FuseId );
+ myDisplayer = new HYDROGUI_Displayer( this );
}
bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
theTypesList << GraphicsView_Viewer::Type();
}
-HYDROGUI_DataModel* HYDROGUI_Module::getModel() const
+void HYDROGUI_Module::update( const int flags )
+{
+ if( !isUpdateEnabled() )
+ return;
+
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+
+ // To prevent calling this method recursively
+ // from one of the methods called below
+ setUpdateEnabled( false );
+
+ if( ( flags & UF_Model ) && getDataModel() )
+ {
+ getDataModel()->update( getStudyId() );
+ }
+ else
+ {
+ /* to do
+ if( ( flags & UF_ObjBrowser ) && getObjectBrowser() )
+ updateObjectBrowser();
+ */
+ }
+
+ if( ( flags & UF_Viewer ) )
+ updateGV( flags & UF_GV_Init,
+ flags & UF_GV_Forced );
+
+ if( ( flags & UF_Controls ) && getApp() )
+ getApp()->updateActions();
+
+ setUpdateEnabled( true );
+
+ QApplication::restoreOverrideCursor();
+}
+
+HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
{
return (HYDROGUI_DataModel*)dataModel();
}
+HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
+{
+ return myDisplayer;
+}
+
+GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theViewerId ) const
+{
+ ViewManagerList aViewManagerList;
+ getApp()->viewManagers( GraphicsView_Viewer::Type(), aViewManagerList );
+
+ ViewManagerList::iterator anIter, anIterEnd = aViewManagerList.end();
+ for( anIter = aViewManagerList.begin(); anIter != anIterEnd; anIter++ )
+ {
+ GraphicsView_ViewManager* aViewManager =
+ dynamic_cast<GraphicsView_ViewManager*>( *anIter );
+ if( aViewManager && aViewManager->getId() == theViewerId )
+ return aViewManager->getViewer();
+ }
+ return NULL;
+}
+
CAM_DataModel* HYDROGUI_Module::createDataModel()
{
return new HYDROGUI_DataModel( this );
}
-void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theMgr )
+void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
{
- LightApp_Module::onViewManagerAdded( theMgr );
- connect( theMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
- this, SLOT( onViewWindowAdded( SUIT_ViewWindow* ) ) );
+ LightApp_Module::onViewManagerAdded( theViewManager );
+
+ if( theViewManager->getType() == GraphicsView_Viewer::Type() )
+ {
+ createSelector( theViewManager ); // replace the default selector
+
+ connect( theViewManager, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
+ this, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
+ }
}
-void HYDROGUI_Module::onViewWindowAdded( SUIT_ViewWindow* theWnd )
+void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
{
- GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theWnd );
+ LightApp_Module::onViewManagerRemoved( theViewManager );
- LightApp_SelectionMgr* aSelMgr = getApp()->selectionMgr();
- LightApp_GVSelector* aSelector = new LightApp_GVSelector( aViewFrame->getViewer(), aSelMgr );
+ createSelector( theViewManager ); // replace the default selector
+}
- GraphicsView_ViewPort* aViewPort = aViewFrame->getViewPort();
+void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theWnd )
+{
+}
+
+void HYDROGUI_Module::updateGV( const bool theIsInit,
+ const bool theIsForced )
+{
+ if( !getDisplayer() )
+ return;
+
+ ViewManagerList aViewManagerList;
+ getApp()->viewManagers( GraphicsView_Viewer::Type(), aViewManagerList );
+
+ ViewManagerList::iterator anIter, anIterEnd = aViewManagerList.end();
+ for( anIter = aViewManagerList.begin(); anIter != anIterEnd; anIter++ )
+ {
+ GraphicsView_ViewManager* aViewManager =
+ dynamic_cast<GraphicsView_ViewManager*>( *anIter );
+ if( aViewManager )
+ getDisplayer()->UpdateAll( aViewManager->getId(), theIsInit, theIsForced );
+ }
+}
+
+void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
+{
+ if( !theViewManager )
+ return;
+
+ LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
+ if( !aSelectionMgr )
+ return;
- GraphicsView_PrsImage* aPrs1 = new GraphicsView_PrsImage();
- QImage anImage1( "W:/Work/HYDRO/data/samples/1.bmp" );
- aPrs1->setImage( anImage1 );
- aPrs1->setName( "example_1" );
- aPrs1->compute();
- aViewPort->addItem( aPrs1 );
+ QString aViewType = theViewManager->getType();
+ if( aViewType != GraphicsView_Viewer::Type() )
+ return;
- GraphicsView_PrsImage* aPrs2 = new GraphicsView_PrsImage();
- QImage anImage2( "W:/Work/HYDRO/data/samples/2.bmp" );
- aPrs2->setImage( anImage2 );
- aPrs2->setName( "example_2" );
- aPrs2->setRotationAngle( 30 );
- aPrs2->setPosition( 200, 50 );
- aPrs2->compute();
- aViewPort->addItem( aPrs2 );
-
- //qApp->processEvents();
- aViewPort->fitAll();
+ GraphicsView_ViewManager* aViewManager =
+ dynamic_cast<GraphicsView_ViewManager*>( theViewManager );
+ if( !aViewManager )
+ return;
+
+ QList<SUIT_Selector*> aSelectorList;
+ aSelectionMgr->selectors( aViewType, aSelectorList );
+
+ // disable all alien selectors
+ QList<SUIT_Selector*>::iterator anIter, anIterEnd = aSelectorList.end();
+ for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ )
+ {
+ SUIT_Selector* aSelector = *anIter;
+ if( aSelector && !dynamic_cast<HYDROGUI_GVSelector*>( aSelector ) )
+ aSelector->setEnabled( false );
+ }
+
+ new HYDROGUI_GVSelector( this, aViewManager->getViewer(), aSelectionMgr );
+}
+
+bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
+{
+ bool aPrevState = myIsUpdateEnabled;
+ myIsUpdateEnabled = theState;
+ return aPrevState;
+}
+
+bool HYDROGUI_Module::isUpdateEnabled() const
+{
+ return myIsUpdateEnabled;
}
#ifndef HYDROGUI_MODULE_H
#define HYDROGUI_MODULE_H
-#include "HYDROGUI.h"
-
#include <LightApp_Module.h>
+class GraphicsView_Viewer;
+
class SUIT_ViewWindow;
class HYDROGUI_DataModel;
+class HYDROGUI_Displayer;
/**\class HYDROGUI_Module
*\brief The class representing the HYDROGUI module
virtual void windows( QMap<int, int>& ) const;
virtual void viewManagers( QStringList& ) const;
- HYDROGUI_DataModel* getModel() const;
+ virtual void update( const int );
+
+ HYDROGUI_DataModel* getDataModel() const;
+ HYDROGUI_Displayer* getDisplayer() const;
+
+ GraphicsView_Viewer* getViewer( const int theViewerId ) const;
protected:
CAM_DataModel* createDataModel();
protected slots:
void onOperation();
virtual void onViewManagerAdded( SUIT_ViewManager* );
- virtual void onViewWindowAdded( SUIT_ViewWindow* );
+ virtual void onViewManagerRemoved( SUIT_ViewManager* );
+ virtual void onViewCreated( SUIT_ViewWindow* );
+
+private:
+ void updateGV( const bool theIsInit = false,
+ const bool theIsForced = false );
+
+ void createSelector( SUIT_ViewManager* viewMgr );
+
+ bool setUpdateEnabled( const bool theState );
+ bool isUpdateEnabled() const;
private:
void CreateActions();
const QString& theImg = QString::null,
const int theKey = 0, const bool isToggle = false,
const QString& theSlot = QString::null );
+
+private:
+ HYDROGUI_Displayer* myDisplayer;
+
+ bool myIsUpdateEnabled;
};
#endif
void HYDROGUI_ObjSelector::OnSelectionChanged()
{
+ /* ouv: to do
if( !myBtn->isChecked() )
return;
}
}
myObjName->setText( anObjName );
+ */
}
QString HYDROGUI_ObjSelector::GetName() const
void HYDROGUI_Operation::startOperation()
{
+ LightApp_Operation::startOperation();
+
doc()->StartOperation();
if( inputPanel() )
{
- connect( inputPanel(), SIGNAL( panelApply() ), this, SLOT( OnApply() ) );
- connect( inputPanel(), SIGNAL( panelCancel() ), this, SLOT( OnCancel() ) );
-
inputPanel()->show();
myModule->getApp()->desktop()->addDockWidget( Qt::RightDockWidgetArea, inputPanel() );
}
}
+void HYDROGUI_Operation::abortOperation()
+{
+ doc()->AbortOperation();
+
+ LightApp_Operation::abortOperation();
+
+ if( inputPanel() )
+ inputPanel()->hide();
+}
+
+void HYDROGUI_Operation::commitOperation()
+{
+ doc()->CommitOperation();
+
+ LightApp_Operation::commitOperation();
+
+ if( inputPanel() )
+ inputPanel()->hide();
+}
+
HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const
{
if( !myPanel )
+ {
( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel();
+ connect( myPanel, SIGNAL( panelApply() ), this, SLOT( OnApply() ) );
+ connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( OnCancel() ) );
+ }
return myPanel;
}
#ifndef HYDROGUI_OPERATION_H
#define HYDROGUI_OPERATION_H
-#include "HYDROGUI.h"
-
#include <LightApp_Operation.h>
class HYDROGUI_Module;
protected:
virtual void startOperation();
+ virtual void abortOperation();
+ virtual void commitOperation();
+
virtual HYDROGUI_InputPanel* createInputPanel() const = 0;
Handle_HYDROData_Document doc() const;
#include "HYDROGUI_Module.h"
#include "HYDROGUI_TwoImagesOp.h"
-#include <HYDROData_Document.h>
-#include <HYDROData_Image.h>
-
#include <CAM_Application.h>
#include <SUIT_Desktop.h>
#include <SUIT_ResourceMgr.h>
#include <QAction>
-#include <QFileDialog>
QAction* HYDROGUI_Module::CreateAction( const int theId, const QString& theSuffix, const QString& theImg,
const int theKey, const bool isToggle, const QString& theSlot )
void HYDROGUI_Module::CreateActions()
{
CreateAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
+ CreateAction( FuseId, "FUSE_IMAGES" );
+ CreateAction( CutId, "CUT_IMAGES" );
}
void HYDROGUI_Module::CreateMenus()
int aHydroMenuIndex = 6; // Edit menu id == 5, View menu id == 10
int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenuIndex );
createMenu( ImportImageId, aHydroId, -1, -1 );
+ createMenu( FuseId, aHydroId, -1, -1 );
+ createMenu( CutId, aHydroId, -1, -1 );
}
void HYDROGUI_Module::CreatePopups()
int anId = actionId( anAction );
if( anId >= 0 )
startOperation( anId );
-
- // tmp
- if( anId == ImportImageId )
- {
- QString aFileName = QFileDialog::getOpenFileName();
- if( !aFileName.isEmpty() )
- {
- int aStudyId = getStudyId();
- Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
- if( !aDocument.IsNull() )
- {
- Handle(HYDROData_Image) anImageObj =
- Handle(HYDROData_Image)::DownCast( aDocument->CreateObject( KIND_IMAGE ) );
- if( !anImageObj.IsNull() )
- {
- static int ImageId = 0;
- anImageObj->SetName( QString( "Image_%1" ).arg( QString::number( ++ImageId ) ) );
-
- QImage anImage( aFileName );
- QTransform aTransform;
- anImageObj->SetImage( anImage );
- anImageObj->SetTrsf( aTransform );
-
- getModel()->updateModel();
- }
- }
- }
- }
}
LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_Prs.h"
+
+//=======================================================================
+// name : HYDROGUI_Prs
+// Purpose : Constructor
+//=======================================================================
+HYDROGUI_Prs::HYDROGUI_Prs( const Handle(HYDROData_Object)& theObject )
+: GraphicsView_Object(),
+ myObject( theObject ),
+ myIsToUpdate( false )
+{
+}
+
+//=======================================================================
+// name : HYDROGUI_Prs
+// Purpose : Destructor
+//=======================================================================
+HYDROGUI_Prs::~HYDROGUI_Prs()
+{
+}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_PRS_H
+#define HYDROGUI_PRS_H
+
+#include <HYDROData_Object.h>
+
+#include <GraphicsView_Object.h>
+
+/*
+ Class : HYDROGUI_Prs
+ Description : Base class for all HYDRO presentation
+*/
+class HYDROGUI_Prs : public GraphicsView_Object
+{
+public:
+ HYDROGUI_Prs( const Handle(HYDROData_Object)& theObject );
+ virtual ~HYDROGUI_Prs();
+
+public:
+ Handle(HYDROData_Object) getObject() const { return myObject; }
+
+ bool getIsToUpdate() const { return myIsToUpdate; }
+ void setIsToUpdate( bool theState ) { myIsToUpdate = theState; }
+
+private:
+ Handle(HYDROData_Object) myObject;
+ bool myIsToUpdate;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_PrsDriver.h"
+
+#include "HYDROGUI_Prs.h"
+
+HYDROGUI_PrsDriver::HYDROGUI_PrsDriver()
+{
+}
+
+HYDROGUI_PrsDriver::~HYDROGUI_PrsDriver()
+{
+}
+
+bool HYDROGUI_PrsDriver::Update( const Handle(HYDROData_Object)& theObj,
+ HYDROGUI_Prs*& thePrs )
+{
+ if ( thePrs )
+ thePrs->setIsToUpdate( false );
+ return true;
+}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_PRSDRIVER_H
+#define HYDROGUI_PRSDRIVER_H
+
+#include <HYDROData_Object.h>
+
+class HYDROGUI_Prs;
+
+/**
+ * \class HYDROGUI_PrsDriver
+ * \brief Base class of presentation driver, which allows to build a
+ * presentation on a basis of data object.
+ */
+class HYDROGUI_PrsDriver
+{
+public:
+ /**
+ * \brief Constructor.
+ */
+ HYDROGUI_PrsDriver();
+
+ /**
+ * \brief Destructor.
+ */
+ virtual ~HYDROGUI_PrsDriver();
+
+public:
+ /**
+ * \brief Virtual method intended to update or create the presentation
+ * on a basis of data object.
+ * \param theObj data object
+ * \param thePrs presentation
+ * \return status of the operation
+ */
+ virtual bool Update( const Handle(HYDROData_Object)& theObj,
+ HYDROGUI_Prs*& thePrs );
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_PrsImage.h"
+
+#include "HYDROGUI_PrsImageFrame.h"
+
+#include <GraphicsView_ViewPort.h>
+
+#include <QCursor>
+
+//=======================================================================
+// name : HYDROGUI_PrsImage
+// Purpose : Constructor
+//=======================================================================
+HYDROGUI_PrsImage::HYDROGUI_PrsImage( const Handle(HYDROData_Object)& theObject )
+: HYDROGUI_Prs( theObject ),
+ myPixmapItem( 0 ),
+ myPrsImageFrame( 0 ),
+ myIsTransformationPointPreview( false ),
+ myTransformationPointMode( None )
+{
+ myHighlightCursor = new QCursor( Qt::PointingHandCursor );
+ myTransformationPointCursor = new QCursor( Qt::CrossCursor );
+}
+
+//=======================================================================
+// name : HYDROGUI_PrsImage
+// Purpose : Destructor
+//=======================================================================
+HYDROGUI_PrsImage::~HYDROGUI_PrsImage()
+{
+ if( myHighlightCursor )
+ {
+ delete myHighlightCursor;
+ myHighlightCursor = 0;
+ }
+
+ if( myTransformationPointCursor )
+ {
+ delete myTransformationPointCursor;
+ myTransformationPointCursor = 0;
+ }
+}
+
+//================================================================
+// Function : setImage
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImage::setImage( const QImage& theImage )
+{
+ myImage = theImage;
+}
+
+//================================================================
+// Function : getImage
+// Purpose :
+//================================================================
+QImage HYDROGUI_PrsImage::getImage() const
+{
+ return myImage;
+}
+
+//================================================================
+// Function : setIsTransformationPointPreview
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImage::setIsTransformationPointPreview( const bool theState )
+{
+ myIsTransformationPointPreview = theState;
+}
+
+//================================================================
+// Function : getIsTransformationPointPreview
+// Purpose :
+//================================================================
+bool HYDROGUI_PrsImage::getIsTransformationPointPreview() const
+{
+ return myIsTransformationPointPreview;
+}
+
+//================================================================
+// Function : setTransformationPointMode
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImage::setTransformationPointMode( const int theMode )
+{
+ myTransformationPointMode = theMode;
+ if( theMode != None )
+ computeTransformationPoints();
+}
+
+//================================================================
+// Function : boundingRect
+// Purpose :
+//================================================================
+QRectF HYDROGUI_PrsImage::boundingRect() const
+{
+ return myPixmapItem->boundingRect();
+}
+
+//================================================================
+// Function : compute
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImage::compute()
+{
+ if( !myPixmapItem )
+ {
+ myPixmapItem = new QGraphicsPixmapItem( this );
+ addToGroup( myPixmapItem );
+ }
+ if( !myPrsImageFrame )
+ {
+ myPrsImageFrame = new HYDROGUI_PrsImageFrame( this );
+ addToGroup( myPrsImageFrame );
+ }
+ myPixmapItem->setPixmap( QPixmap::fromImage( myImage ) );
+ myPrsImageFrame->compute();
+}
+
+//================================================================
+// Function : addTo
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImage::addTo( GraphicsView_ViewPort* theViewPort )
+{
+ GraphicsView_Object::addTo( theViewPort );
+ theViewPort->addItem( myPrsImageFrame );
+
+ double aZValue = 0;
+ GraphicsView_ObjectListIterator anIter( theViewPort->getObjects() );
+ while( anIter.hasNext() )
+ {
+ if( HYDROGUI_PrsImage* aPrs = dynamic_cast<HYDROGUI_PrsImage*>( anIter.next() ) )
+ {
+ double aZValueRef = aPrs->zValue();
+ aZValue = qMax( aZValue, aZValueRef );
+ }
+ }
+ setZValue( aZValue + 1 );
+}
+
+//================================================================
+// Function : removeFrom
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImage::removeFrom( GraphicsView_ViewPort* theViewPort )
+{
+ GraphicsView_Object::removeFrom( theViewPort );
+ theViewPort->removeItem( myPrsImageFrame );
+}
+
+//================================================================
+// Function : checkHighlight
+// Purpose :
+//================================================================
+bool HYDROGUI_PrsImage::checkHighlight( double theX, double theY, QCursor& theCursor ) const
+{
+ QRect aRect = myPixmapItem->boundingRect().toRect();
+ QPolygon aPolygon = sceneTransform().mapToPolygon( aRect );
+ if( aPolygon.containsPoint( QPoint( theX, theY ), Qt::OddEvenFill ) )
+ {
+ if( myIsTransformationPointPreview )
+ {
+ if( myTransformationPointMode != None )
+ theCursor = *getTransformationPointCursor();
+ }
+ else
+ theCursor = *getHighlightCursor();
+ return true;
+ }
+ return false;
+}
+
+//================================================================
+// Function : select
+// Purpose :
+//================================================================
+bool HYDROGUI_PrsImage::select( double theX, double theY, const QRectF& theRect )
+{
+ if( myIsTransformationPointPreview )
+ {
+ if( myTransformationPointMode == None || !theRect.isEmpty() )
+ return false;
+
+ TransformationPoint& aTransformationPoint = myTransformationPointMap[ myTransformationPointMode ];
+ aTransformationPoint.Point = QPoint( (int)theX, (int)theY );
+ computeTransformationPoints();
+ return true;
+ }
+
+ bool anIsSelected = GraphicsView_Object::select( theX, theY, theRect );
+ myPrsImageFrame->updateVisibility();
+ return anIsSelected;
+}
+
+//================================================================
+// Function : unselect
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImage::unselect()
+{
+ GraphicsView_Object::unselect();
+ myPrsImageFrame->updateVisibility();
+}
+
+//================================================================
+// Function : setSelected
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImage::setSelected( bool theState )
+{
+ GraphicsView_Object::setSelected( theState );
+ myPrsImageFrame->updateVisibility();
+}
+
+//================================================================
+// Function : computeTransformationPoints
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImage::computeTransformationPoints()
+{
+ if( myTransformationPointMap.isEmpty() )
+ {
+ int aWidth = myImage.width();
+ int aHeight = myImage.height();
+
+ for( int aPointType = PointA; aPointType <= PointC; aPointType++ )
+ {
+ TransformationPoint aTransformationPoint;
+
+ QPoint aPoint;
+ QString aCaption;
+ QColor aColor = Qt::black;
+ switch( aPointType )
+ {
+ case PointA:
+ aPoint = QPoint( 0, 0 );
+ aCaption = "A";
+ aColor = Qt::darkRed;
+ break;
+ case PointB:
+ aPoint = QPoint( aWidth, 0 );
+ aCaption = "B";
+ aColor = Qt::darkGreen;
+ break;
+ case PointC:
+ aPoint = QPoint( 0, aHeight );
+ aCaption = "C";
+ aColor = Qt::darkBlue;
+ break;
+ }
+
+ aTransformationPoint.Point = aPoint;
+ aTransformationPoint.Caption = aCaption;
+
+ aTransformationPoint.PointItem = new QGraphicsEllipseItem( this );
+ aTransformationPoint.PointItem->setVisible( false );
+ aTransformationPoint.PointItem->setPen( QPen( aColor ) );
+ aTransformationPoint.PointItem->setBrush( QBrush( aColor ) );
+
+ aTransformationPoint.CaptionItem = new QGraphicsSimpleTextItem( aCaption, this );
+ aTransformationPoint.CaptionItem->setVisible( false );
+ aTransformationPoint.CaptionItem->setPen( QPen( aColor ) );
+ aTransformationPoint.CaptionItem->setBrush( QBrush( aColor ) );
+
+ myTransformationPointMap[ aPointType ] = aTransformationPoint;
+ }
+ }
+
+ bool anIsVisible = myIsTransformationPointPreview;
+ for( int aPointType = PointA; aPointType <= PointC; aPointType++ )
+ {
+ TransformationPoint& aTransformationPoint = myTransformationPointMap[ aPointType ];
+
+ double aRadius = 5;
+ const QPointF& aPoint = aTransformationPoint.Point;
+ QRectF aRect( aPoint - QPointF( aRadius, aRadius ), QSizeF( aRadius * 2 + 1, aRadius * 2 + 1 ) );
+ aTransformationPoint.PointItem->setRect( aRect );
+ aTransformationPoint.PointItem->setVisible( anIsVisible );
+
+ QPointF aCaptionShift( -aRadius * 2, aRadius * 2 );
+ aTransformationPoint.CaptionItem->setPos( aPoint + aCaptionShift );
+ aTransformationPoint.CaptionItem->setVisible( anIsVisible );
+ }
+}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_PRSIMAGE_H
+#define HYDROGUI_PRSIMAGE_H
+
+#include "HYDROGUI_Prs.h"
+
+class HYDROGUI_PrsImageFrame;
+
+/*
+ Class : HYDROGUI_PrsImage
+ Description : Presentation for image object
+*/
+class HYDROGUI_PrsImage : public HYDROGUI_Prs
+{
+public:
+ enum TransformationPointType { None = 0, PointA, PointB, PointC };
+ struct TransformationPoint
+ {
+ QPoint Point;
+ QString Caption;
+ QGraphicsEllipseItem* PointItem;
+ QGraphicsSimpleTextItem* CaptionItem;
+ };
+ typedef QMap < int, TransformationPoint > TransformationPointMap;
+ typedef QMapIterator< int, TransformationPoint > TransformationPointMapIterator;
+
+public:
+ HYDROGUI_PrsImage( const Handle(HYDROData_Object)& theObject );
+ virtual ~HYDROGUI_PrsImage();
+
+public:
+ void setImage( const QImage& theImage );
+ QImage getImage() const;
+
+ void setIsTransformationPointPreview( const bool theState );
+ bool getIsTransformationPointPreview() const;
+
+ void setTransformationPointMode( const int theMode );
+ const TransformationPointMap& getTransformationPointMap() const { return myTransformationPointMap; }
+
+public:
+ // from QGraphicsItem
+ virtual QRectF boundingRect() const;
+
+ // from GraphicsView_Object
+ virtual void compute();
+
+ virtual void addTo( GraphicsView_ViewPort* theViewPort );
+ virtual void removeFrom( GraphicsView_ViewPort* theViewPort );
+
+ virtual bool isMovable() const { return false; }
+
+ virtual bool checkHighlight( double theX, double theY, QCursor& theCursor ) const;
+
+ virtual bool select( double theX, double theY, const QRectF& theRect );
+ virtual void unselect();
+ virtual void setSelected( bool theState );
+
+protected:
+ void computeTransformationPoints();
+
+protected:
+ QCursor* getHighlightCursor() const { return myHighlightCursor; }
+ QCursor* getTransformationPointCursor() const { return myTransformationPointCursor; }
+
+protected:
+ QImage myImage;
+
+ QGraphicsPixmapItem* myPixmapItem;
+ HYDROGUI_PrsImageFrame* myPrsImageFrame;
+
+ bool myIsTransformationPointPreview;
+ int myTransformationPointMode;
+ TransformationPointMap myTransformationPointMap;
+
+private:
+ QCursor* myHighlightCursor;
+ QCursor* myTransformationPointCursor;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_PrsImageDriver.h"
+
+#include "HYDROGUI_PrsImage.h"
+
+#include <HYDROData_Image.h>
+
+HYDROGUI_PrsImageDriver::HYDROGUI_PrsImageDriver()
+:HYDROGUI_PrsDriver()
+{
+}
+
+HYDROGUI_PrsImageDriver::~HYDROGUI_PrsImageDriver()
+{
+}
+
+bool HYDROGUI_PrsImageDriver::Update( const Handle(HYDROData_Object)& theObj,
+ HYDROGUI_Prs*& thePrs )
+{
+ HYDROGUI_PrsDriver::Update( theObj, thePrs );
+
+ if( theObj.IsNull() )
+ return false;
+
+ Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( theObj );
+ if( anImage.IsNull() )
+ return false;
+
+ if( !thePrs )
+ thePrs = new HYDROGUI_PrsImage( theObj );
+
+ HYDROGUI_PrsImage* aPrsImage = (HYDROGUI_PrsImage*)thePrs;
+
+ aPrsImage->setName( anImage->GetName() );
+ aPrsImage->setImage( anImage->Image() );
+ aPrsImage->setTransform( anImage->Trsf() );
+
+ aPrsImage->compute();
+
+ return true;
+}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_PRSIMAGEDRIVER_H
+#define HYDROGUI_PRSIMAGEDRIVER_H
+
+#include <HYDROGUI_PrsDriver.h>
+
+/**
+ * \class HYDROGUI_PrsImageDriver
+ * \brief Presentation driver for image objects.
+ */
+class HYDROGUI_PrsImageDriver : public HYDROGUI_PrsDriver
+{
+public:
+ /**
+ * \brief Constructor.
+ */
+ HYDROGUI_PrsImageDriver();
+
+ /**
+ * \brief Destructor.
+ */
+ virtual ~HYDROGUI_PrsImageDriver();
+
+public:
+ /**
+ * \brief Update or create the image presentation on a basis of data object.
+ * \param theObj data object
+ * \param thePrs presentation
+ * \return status of the operation
+ */
+ virtual bool Update( const Handle(HYDROData_Object)& theObj,
+ HYDROGUI_Prs*& thePrs );
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_PrsImageFrame.h"
+
+#include "HYDROGUI_PrsImage.h"
+
+#include <QPainter>
+
+#define FRAME_Z_VALUE 1000
+#define ANCHOR_RADIUS 3
+#define EPSILON 1e-6
+
+//=======================================================================
+// name : HYDROGUI_PrsImageFrame
+// Purpose : Constructor
+//=======================================================================
+HYDROGUI_PrsImageFrame::HYDROGUI_PrsImageFrame( HYDROGUI_PrsImage* thePrsImage )
+: GraphicsView_Object( thePrsImage ),
+ myPrsImage( thePrsImage )
+{
+}
+
+//=======================================================================
+// name : HYDROGUI_PrsImageFrame
+// Purpose : Destructor
+//=======================================================================
+HYDROGUI_PrsImageFrame::~HYDROGUI_PrsImageFrame()
+{
+}
+
+//================================================================
+// Function : boundingRect
+// Purpose :
+//================================================================
+QRectF HYDROGUI_PrsImageFrame::boundingRect() const
+{
+ QRectF aRect;
+ AnchorMapIterator anIter( myAnchorMap );
+ while( anIter.hasNext() )
+ {
+ if( QGraphicsEllipseItem* anAnchorItem = anIter.next().value() )
+ {
+ QRectF anAnchorRect = anAnchorItem->boundingRect();
+ if( !anAnchorRect.isNull() )
+ {
+ if( aRect.isNull() )
+ aRect = anAnchorRect;
+ else
+ aRect |= anAnchorRect;
+ }
+ }
+ }
+ return aRect;
+}
+
+//================================================================
+// Function : compute
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImageFrame::compute()
+{
+ if( myAnchorMap.isEmpty() )
+ {
+ for( int aType = TopLeft; aType <= BottomRight; aType++ )
+ {
+ UnscaledGraphicsEllipseItem* anAnchorItem = new UnscaledGraphicsEllipseItem( this );
+ anAnchorItem->setBrush( QBrush( Qt::white ) );
+ myAnchorMap.insert( aType, anAnchorItem );
+ addToGroup( anAnchorItem );
+ }
+ }
+
+ setZValue( FRAME_Z_VALUE );
+
+ computeAnchorItems();
+ updateVisibility();
+}
+
+//================================================================
+// Function : computeAnchorItems
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImageFrame::computeAnchorItems()
+{
+ if( !myPrsImage )
+ return;
+
+ QRectF aRect = myPrsImage->boundingRect();
+
+ QMap<int, QPointF> anAnchorPointMap;
+ anAnchorPointMap[ TopLeft ] = aRect.topLeft();
+ anAnchorPointMap[ TopRight ] = aRect.topRight();
+ anAnchorPointMap[ BottomLeft ] = aRect.bottomLeft();
+ anAnchorPointMap[ BottomRight ] = aRect.bottomRight();
+
+ qreal ar = ANCHOR_RADIUS;
+ QMapIterator<int, QPointF> anIter( anAnchorPointMap );
+ while( anIter.hasNext() )
+ {
+ int anAnchorType = anIter.next().key();
+ const QPointF& anAnchorPoint = anIter.value();
+
+ QRectF anAnchorRect( anAnchorPoint - QPointF( ar, ar ), QSizeF( ar * 2, ar * 2 ) );
+ myAnchorMap[ anAnchorType ]->setRect( anAnchorRect );
+ myAnchorMap[ anAnchorType ]->setBasePoint( anAnchorPoint );
+ }
+}
+
+//================================================================
+// Function : updateVisibility
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImageFrame::updateVisibility()
+{
+ setVisible( myPrsImage && myPrsImage->isSelected() );
+}
+
+//=======================================================================
+// name : HYDROGUI_PrsImageFrame::UnscaledGraphicsEllipseItem
+// Purpose : Constructor
+//=======================================================================
+HYDROGUI_PrsImageFrame::UnscaledGraphicsEllipseItem::UnscaledGraphicsEllipseItem( QGraphicsItem* theParent )
+: QGraphicsEllipseItem( theParent )
+{
+}
+
+//=======================================================================
+// name : HYDROGUI_PrsImageFrame::UnscaledGraphicsEllipseItem
+// Purpose : Destructor
+//=======================================================================
+HYDROGUI_PrsImageFrame::UnscaledGraphicsEllipseItem::~UnscaledGraphicsEllipseItem()
+{
+}
+
+//================================================================
+// Function : boundingRect
+// Purpose :
+//================================================================
+QRectF HYDROGUI_PrsImageFrame::UnscaledGraphicsEllipseItem::boundingRect() const
+{
+ QRectF aRect = QGraphicsEllipseItem::boundingRect();
+
+ GraphicsView_Object* aParent = dynamic_cast<GraphicsView_Object*>( parentItem() );
+ if( !aParent )
+ return aRect;
+
+ QTransform aTransform = aParent->getViewTransform();
+ double aScale = aTransform.m11(); // same as m22(), viewer specific
+ if( fabs( aScale ) < EPSILON )
+ return aRect;
+
+ QPointF aCenter = aRect.center();
+ double aWidth = aRect.width() / aScale;
+ double aHeight = aRect.height() / aScale;
+
+ aRect = QRectF( aCenter.x() - aWidth / 2, aCenter.y() - aHeight / 2, aWidth, aHeight );
+ return aRect;
+}
+
+//================================================================
+// Function : GenerateTranslationOnlyTransform
+// Purpose :
+//================================================================
+static QTransform GenerateTranslationOnlyTransform( const QTransform &theOriginalTransform,
+ const QPointF &theTargetPoint )
+{
+ qreal dx = theOriginalTransform.m11() * theTargetPoint.x() - theTargetPoint.x() +
+ theOriginalTransform.m21() * theTargetPoint.y() +
+ theOriginalTransform.m31();
+ qreal dy = theOriginalTransform.m22() * theTargetPoint.y() - theTargetPoint.y() +
+ theOriginalTransform.m12() * theTargetPoint.x() +
+ theOriginalTransform.m32();
+ return QTransform::fromTranslate( dx, dy );
+}
+
+//================================================================
+// Function : paint
+// Purpose :
+//================================================================
+void HYDROGUI_PrsImageFrame::UnscaledGraphicsEllipseItem::paint(
+ QPainter* thePainter,
+ const QStyleOptionGraphicsItem* theOption,
+ QWidget* theWidget )
+{
+ thePainter->save();
+ thePainter->setTransform( GenerateTranslationOnlyTransform( thePainter->transform(),
+ myBasePoint ) );
+
+ QGraphicsEllipseItem::paint( thePainter, theOption, theWidget );
+ thePainter->restore();
+}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_PRSIMAGEFRAME_H
+#define HYDROGUI_PRSIMAGEFRAME_H
+
+#include <GraphicsView_Object.h>
+
+#include <QGraphicsEllipseItem>
+
+class HYDROGUI_PrsImage;
+
+/*
+ Class : HYDROGUI_PrsImageFrame
+ Description : Presentation for image frame object
+*/
+class HYDROGUI_PrsImageFrame : public GraphicsView_Object
+{
+public:
+ class UnscaledGraphicsEllipseItem;
+
+ enum AnchorType { Undefined = 0, TopLeft, TopRight, BottomLeft, BottomRight };
+
+ typedef QMap <int, UnscaledGraphicsEllipseItem*> AnchorMap;
+ typedef QMapIterator<int, UnscaledGraphicsEllipseItem*> AnchorMapIterator;
+
+public:
+ HYDROGUI_PrsImageFrame( HYDROGUI_PrsImage* thePrsImage );
+ virtual ~HYDROGUI_PrsImageFrame();
+
+public:
+ // from QGraphicsItem
+ virtual QRectF boundingRect() const;
+
+ // from GraphicsView_Object
+ virtual void compute();
+
+ virtual bool hasSpecificZValue() const { return true; }
+
+ virtual bool isSelectable() const { return false; }
+ virtual bool isMovable() const { return false; }
+
+public:
+ void computeAnchorItems();
+ void updateVisibility();
+
+protected:
+ HYDROGUI_PrsImage* myPrsImage;
+ AnchorMap myAnchorMap;
+};
+
+/*
+ Class : UnscaledGraphicsEllipseItem
+ Description : Class for unscaled ellipse item
+*/
+class HYDROGUI_PrsImageFrame::UnscaledGraphicsEllipseItem : public QGraphicsEllipseItem
+{
+public:
+ UnscaledGraphicsEllipseItem( QGraphicsItem* );
+ virtual ~UnscaledGraphicsEllipseItem();
+
+public:
+ void setBasePoint( const QPointF& thePoint ) { myBasePoint = thePoint; }
+ const QPointF& getBasePoint() const { return myBasePoint; }
+
+public:
+ virtual QRectF boundingRect() const;
+ virtual void paint( QPainter*, const QStyleOptionGraphicsItem*, QWidget* );
+
+private:
+ QPointF myBasePoint;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_Tool.h"
+
+#include "HYDROGUI_DataModel.h"
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_Prs.h"
+
+#include <HYDROData_Document.h>
+#include <HYDROData_Image.h>
+#include <HYDROData_Iterator.h>
+
+#include <LightApp_Application.h>
+
+#include <QtxWorkstack.h>
+
+#include <STD_TabDesktop.h>
+
+#include <SUIT_Study.h>
+#include <SUIT_ViewManager.h>
+#include <SUIT_ViewWindow.h>
+
+void HYDROGUI_Tool::SetActiveViewManager( HYDROGUI_Module* theModule,
+ SUIT_ViewManager* theViewManager )
+{
+ if( theViewManager )
+ if( SUIT_ViewWindow* aViewWindow = theViewManager->getActiveView() )
+ if( STD_TabDesktop* aTabDesktop = dynamic_cast<STD_TabDesktop*>( theModule->getApp()->desktop() ) )
+ if( QtxWorkstack* aWorkstack = aTabDesktop->workstack() )
+ aWorkstack->setActiveWindow( aViewWindow );
+}
+
+void HYDROGUI_Tool::GetPrsSubObjects( const HYDROGUI_DataModel* theGUIModel,
+ const int theViewerId, // currently unused
+ HYDROData_SequenceOfObjects& theSeq )
+{
+ if( !theGUIModel )
+ return;
+
+ const int aStudyId = theGUIModel->module()->application()->activeStudy()->id();
+
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
+ if( aDocument.IsNull() )
+ return;
+
+ HYDROData_Iterator anIterator( aDocument, KIND_IMAGE );
+ for( ; anIterator.More(); anIterator.Next() )
+ {
+ Handle(HYDROData_Image) anImageObj =
+ Handle(HYDROData_Image)::DownCast( anIterator.Current() );
+ if( !anImageObj.IsNull() )
+ theSeq.Append( anImageObj );
+ }
+}
+
+HYDROGUI_Prs* HYDROGUI_Tool::GetPresentation( const Handle(HYDROData_Object)& theObj,
+ const GraphicsView_ObjectList& theObjects )
+{
+ GraphicsView_ObjectListIterator anIter( theObjects );
+ while( anIter.hasNext() )
+ if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
+ if( aPrs->getObject()->Label() == theObj->Label() )
+ return aPrs;
+ return NULL;
+}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_TOOL_H
+#define HYDROGUI_TOOL_H
+
+#include <HYDROData_Object.h>
+
+#include <GraphicsView_Defs.h>
+
+class SUIT_ViewManager;
+
+class HYDROGUI_DataModel;
+class HYDROGUI_Module;
+class HYDROGUI_Prs;
+
+/**
+ * \class HYDROGUI_Tool
+ * \brief This class contains several useful methods.
+ */
+class HYDROGUI_Tool
+{
+public:
+ /**
+ * \brief Set the specified view manager to be active on the desktop.
+ * \param theModule module
+ * \param theViewManager view manager
+ */
+ static void SetActiveViewManager( HYDROGUI_Module* theModule,
+ SUIT_ViewManager* theViewManager );
+
+ /**
+ * \brief Get sub-objects to build presentations.
+ * \param theGUIModel data model
+ * \param theViewerId viewer id
+ * \param theSeq sequence of sub-objects
+ */
+ static void GetPrsSubObjects( const HYDROGUI_DataModel* theGUIModel,
+ const int theViewerId,
+ HYDROData_SequenceOfObjects& theSeq );
+
+ /**
+ * \brief Get presentation built for specified data object.
+ * \param theObj data object
+ * \param theObjects list of existing presentations
+ * \return presentation
+ */
+ static HYDROGUI_Prs* GetPresentation( const Handle(HYDROData_Object)& theObj,
+ const GraphicsView_ObjectList& theObjects );
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_UPDATEFLAGS_H
+#define HYDROGUI_UPDATEFLAGS_H
+
+/**
+ * \enum HYDRO_UpdateFlags
+ * Enumeration for update flags. First byte is reserved for LightApp_Module.
+ * Modules derived from this model must use other 3 bytes to define their
+ * own update flags.
+ */
+typedef enum
+{
+ UF_GV_Init = 0x00000020, //!< initial update (used with UF_Viewer)
+ UF_GV_Forced = 0x00000040, //!< to force recomputing all presentations (used with UF_Viewer)
+} HYDRO_UpdateFlags;
+
+#endif
<context>
<name>@default</name>
<message>
- <source>TEST_ICO</source>
- <translation>icon_test.png</translation>
+ <source>ARROW_RIGHT_ICO</source>
+ <translation>icon_arrow_right.png</translation>
+ </message>
+ <message>
+ <source>BROWSE_ICO</source>
+ <translation>icon_browse.png</translation>
</message>
</context>
</TS>
<TS version="1.1" >
<context>
<name>@default</name>
+ <message>
+ <source>INSUFFICIENT_INPUT_DATA</source>
+ <translation>Insufficient input data</translation>
+ </message>
+ <message>
+ <source>INPUT_VALID_DATA</source>
+ <translation>Please enter valid data and try again.</translation>
+ </message>
</context>
<context>
<name>HYDROGUI_DataModel</name>
<translation>Study could not be saved</translation>
</message>
</context>
+ <context>
+ <name>HYDROGUI_InputPanel</name>
+ <message>
+ <source>APPLY</source>
+ <translation>Apply</translation>
+ </message>
+ <message>
+ <source>CANCEL</source>
+ <translation>Cancel</translation>
+ </message>
+ <message>
+ <source>HELP</source>
+ <translation>Help</translation>
+ </message>
+ </context>
+ <context>
+ <name>HYDROGUI_ImportImageDlg</name>
+ <message>
+ <source>BROWSE_IMAGE_FILE</source>
+ <translation>Browse image file</translation>
+ </message>
+ <message>
+ <source>FILE_NAME</source>
+ <translation>File name</translation>
+ </message>
+ <message>
+ <source>IMAGE_FILTER</source>
+ <translation>Image files (*.bmp *.jpg *.jpeg *.png);;All files (*.* *)</translation>
+ </message>
+ <message>
+ <source>IMPORT_IMAGE_FROM_FILE</source>
+ <translation>Import image from file</translation>
+ </message>
+ <message>
+ <source>MAPPING</source>
+ <translation>Mapping</translation>
+ </message>
+ <message>
+ <source>POINT_A</source>
+ <translation>Point A</translation>
+ </message>
+ <message>
+ <source>POINT_B</source>
+ <translation>Point B</translation>
+ </message>
+ <message>
+ <source>POINT_C</source>
+ <translation>Point C</translation>
+ </message>
+ </context>
+ <context>
+ <name>HYDROGUI_ImportImageOp</name>
+ <message>
+ <source>IMPORT_IMAGE</source>
+ <translation>Import image</translation>
+ </message>
+ <message>
+ <source>MAPPING</source>
+ <translation>Mapping</translation>
+ </message>
+ </context>
<context>
<name>HYDROGUI_Module</name>
+ <message>
+ <source>DSK_CUT_IMAGES</source>
+ <translation>Cut images</translation>
+ </message>
+ <message>
+ <source>DSK_FUSE_IMAGES</source>
+ <translation>Fuse images</translation>
+ </message>
<message>
<source>DSK_IMPORT_IMAGE</source>
<translation>Import image</translation>
</message>
+ <message>
+ <source>MEN_CUT_IMAGES</source>
+ <translation>Cut images</translation>
+ </message>
+ <message>
+ <source>MEN_FUSE_IMAGES</source>
+ <translation>Fuse images</translation>
+ </message>
<message>
<source>MEN_DESK_HYDRO</source>
<translation>HYDRO</translation>
<source>MEN_IMPORT_IMAGE</source>
<translation>Import image</translation>
</message>
+ <message>
+ <source>STB_CUT_IMAGES</source>
+ <translation>Cut images</translation>
+ </message>
+ <message>
+ <source>STB_FUSE_IMAGES</source>
+ <translation>Fuse images</translation>
+ </message>
<message>
<source>STB_IMPORT_IMAGE</source>
<translation>Import image</translation>