]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Feature 32: Image presentation in OCCViewer.
authorouv <ouv@opencascade.com>
Thu, 3 Oct 2013 09:50:20 +0000 (09:50 +0000)
committerouv <ouv@opencascade.com>
Thu, 3 Oct 2013 09:50:20 +0000 (09:50 +0000)
15 files changed:
src/HYDROGUI/HYDROGUI_AISCurve.cxx
src/HYDROGUI/HYDROGUI_AISCurve.h
src/HYDROGUI/HYDROGUI_DataObject.cxx
src/HYDROGUI/HYDROGUI_DataObject.h
src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx
src/HYDROGUI/HYDROGUI_ImportImageOp.cxx
src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx
src/HYDROGUI/HYDROGUI_PolylineOp.cxx
src/HYDROGUI/HYDROGUI_PolylineOp.h
src/HYDROGUI/HYDROGUI_Shape.cxx
src/HYDROGUI/HYDROGUI_Shape.h
src/HYDROGUI/HYDROGUI_Tool.cxx
src/HYDROGUI/HYDROGUI_Tool.h
src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx
src/HYDROGUI/HYDROGUI_UpdateImageOp.cxx

index 67265afd33932f8de89d669ed08c7b4799c01375..c8366ebc2e4da0e05d3e7dcc134df966fa1da522 100755 (executable)
@@ -189,6 +189,13 @@ void HYDROGUI_AISCurve::Display()
   }
 }
 
+void HYDROGUI_AISCurve::Erase()
+{
+  for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){
+    myCurveRepresentation[i]->Erase();
+  }
+}
+
 void HYDROGUI_AISCurve::buildCurve()
 {
   for( int i = 0 ; i < myCurveRepresentation.size() ; i++ ){
index 5750ae6a142849666db64313850b62858a4d5312..f1fca75aefcaf7a5e9b0c709ff8e96cf2bebbc3a 100755 (executable)
@@ -56,6 +56,7 @@ public:
   void setCurve( CurveCreator_Curve* theCurve );
 
   void Display();
+  void Erase();
 
   virtual void pointInserted( int theSection, int theIndx );
 
index f0b47e22b4beb40f0440981ae3271517a0b6a97f..b2b4d05e971784599368176c4f5a6ed448ce1dc7 100644 (file)
@@ -72,14 +72,17 @@ QFont HYDROGUI_DataObject::font( const int theId ) const
   return aFont;
 }
 
-QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Object)& theObject )
+QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Object)& theObject,
+                                              const bool theWithPrefix )
 {
   QString aEntryStr = QString::null;
   if( !theObject.IsNull() )
   {
     TCollection_AsciiString aLabEntr;
     TDF_Tool::Entry( theObject->Label(), aLabEntr );
-    aEntryStr = HYDROGUI_DataObject::entryPrefix() + QString( aLabEntr.ToCString() );
+    aEntryStr = aLabEntr.ToCString();
+    if( theWithPrefix )
+      aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
   }
   return aEntryStr;
 }
index edb79f02e7006e87eea1ef74943fd9c5b18aa3c7..69693349d7fd1e519cdd089f8824c86d17890966 100644 (file)
@@ -91,7 +91,8 @@ public:
   /**
    * Returns the full entry for the specified data object.
    */
-  static QString dataObjectEntry( const Handle(HYDROData_Object)& theObject );
+  static QString dataObjectEntry( const Handle(HYDROData_Object)& theObject,
+                                  const bool theWithPrefix = true );
 
 protected:
   Handle(HYDROData_Object) myData; ///< object from data model
index a8ccf8a5df44491d4c50d522672df72bffc4b39d..01a4b1552cd60cd8bbd84ae0d156c5d7c32fc288 100644 (file)
@@ -512,19 +512,21 @@ void HYDROGUI_ImportImageDlg::initializePointSelection()
   blockSignalsLambert( false );
   */
 
-  double aCartX0 = 600000;
-  double aCartY0 = 6800000;
+  //double aCartX0 = 600000;
+  //double aCartY0 = 6800000;
+  double aCartX0 = 0;
+  double aCartY0 = 0;
 
   blockSignalsCartesian( true );
 
   myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
   myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 );
 
-  myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + 1000 );
+  myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + 500 );
   myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 );
 
   myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
-  myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 + 1000 );
+  myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 + 500 );
 
   for( int aPointType = HYDROGUI_PrsImage::PointA;
        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
index 5f73b4b0d870ad5726d6d59f3558f7e15c3733e2..46cbd7ebaf560f42cf84b05f5b7c7dc1127924e3 100644 (file)
@@ -339,7 +339,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
   if( myIsEdit )
     anImageObj->Update();
 
-  theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced;
+  theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;
   return true;
 }
 
index d20db2484db4ddc086d0555884daf1000bc1470c..8be446e4555cf90efa0fb637b9aaec86989e9f9b 100644 (file)
@@ -145,7 +145,8 @@ HYDROGUI_Shape* HYDROGUI_OCCDisplayer::createShape( const int
     return aResShape;
 
   ObjectKind anObjectKind = theObject->GetKind();
-  if ( anObjectKind != KIND_POLYLINE &&
+  if ( anObjectKind != KIND_IMAGE &&
+       anObjectKind != KIND_POLYLINE &&
        anObjectKind != KIND_ZONE )
     return aResShape;
 
index b8b19f763778e2b1a2cbb63b3c2aef813004fc0a..2aa8ccac9b65d2e94649539338dc8b08ce95362d 100755 (executable)
 
 HYDROGUI_PolylineOp::HYDROGUI_PolylineOp( HYDROGUI_Module* theModule, bool theIsEdit )
 : HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myCurve(NULL), 
-  myActiveViewManager(NULL), myPreviewViewManager(NULL), myAISCurve(NULL)
+  myViewManager(NULL), myAISCurve(NULL)
 {
   setName( theIsEdit ? tr( "EDIT_POLYLINE" ) : tr( "CREATE_POLYLINE" ) );
 }
 
 HYDROGUI_PolylineOp::~HYDROGUI_PolylineOp()
 {
-  closePreview();
-}
-
-HYDROGUI_InputPanel* HYDROGUI_PolylineOp::createInputPanel() const
-{
-  HYDROGUI_PolylineDlg* aDlg = new HYDROGUI_PolylineDlg( module(), getName() );
-  connect( aDlg ,SIGNAL( selectionChanged() ), this, SLOT( onEditorSelectionChanged() ) );
-  return aDlg;
-}
-
-bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags,
-                                        QString& theErrorMsg )
-{
-  HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
-
-  int aStudyId = module()->getStudyId();
-  bool aHasDoc = HYDROData_Document::HasDocument(aStudyId);
-  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
-  if( aDocument.IsNull() )
-    return false;
-
-  Handle(HYDROData_Polyline) aPolylineObj;
-  if( myIsEdit ){
-    aPolylineObj = myEditedObject;
-  }
-  else{
-    aPolylineObj = Handle(HYDROData_Polyline)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
-  }
-
-  if( aPolylineObj.IsNull() )
-    return false;
-
-  QString aPolylineName = aPanel->getPolylineName();
-  aPolylineObj->SetName(aPolylineName);
-  int aDimInt = 3;
-  if( myCurve->getDimension() == CurveCreator::Dim2d )
-    aDimInt = 2;
-  aPolylineObj->setDimension(aDimInt);
-  QList<PolylineSection> aPolylineData;
-  for( int i=0 ; i < myCurve->getNbSections() ; i++ ){
-    PolylineSection aSect;
-    aSect.mySectionName = HYDROGUI_Tool::ToExtString( QString::fromLocal8Bit(myCurve->getSectionName(i).c_str()));
-    aSect.myIsClosed = myCurve->isClosed(i);
-    aSect.myType = PolylineSection::SECTION_POLYLINE;
-    if( myCurve->getType(i) == CurveCreator::BSpline ){
-      aSect.myType = PolylineSection::SECTION_SPLINE;
-    }
-    CurveCreator::Coordinates aCoords = myCurve->getPoints(i);
-    for( int j = 0 ; j < aCoords.size() ; j++ ){
-      aSect.myCoords << aCoords.at(j);
-    }
-    aPolylineData << aSect;
-  }
-  aPolylineObj->setPolylineData(aPolylineData);
-
-  theUpdateFlags = UF_Model;
-  module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), aPolylineObj, true );
-  return true;
-}
-
-void HYDROGUI_PolylineOp::onCreatePreview()
-{
-  LightApp_Application* anApp = module()->getApp();
-
-  myActiveViewManager = anApp->activeViewManager();
-
-  myPreviewViewManager =
-    dynamic_cast<OCCViewer_ViewManager*>( anApp->createViewManager( OCCViewer_Viewer::Type() ) );
-  if( myPreviewViewManager )
-  {
-    connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
-             this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
-
-    //anApp->selectionMgr()->setEnabled(false); // what the hell?!
-    myPreviewViewManager->setTitle( tr( "CREATE_POLYLINE" ) );
-    OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
-    aViewer->enableSelection(true);
-    aViewer->enableMultiselection(true);
-    Handle_AIS_InteractiveContext aCtx = aViewer->getAISContext();
-
-    OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView();
-    vw->onTopView();
-
-    myAISCurve = new HYDROGUI_AISCurve(myCurve, aCtx);
-
-    myAISCurve->Display();
-  }
+  erasePreview();
 }
 
 void HYDROGUI_PolylineOp::startOperation()
@@ -189,23 +103,80 @@ void HYDROGUI_PolylineOp::startOperation()
     myAISCurve->setCurve(myCurve);
   if( anOldCurve )
     delete anOldCurve;
-  onCreatePreview();
+  displayPreview();
 }
 
 void HYDROGUI_PolylineOp::abortOperation()
 {
-  closePreview();
+  erasePreview();
 
   HYDROGUI_Operation::abortOperation();
 }
 
 void HYDROGUI_PolylineOp::commitOperation()
 {
-  closePreview();
+  erasePreview();
 
   HYDROGUI_Operation::commitOperation();
 }
 
+HYDROGUI_InputPanel* HYDROGUI_PolylineOp::createInputPanel() const
+{
+  HYDROGUI_PolylineDlg* aDlg = new HYDROGUI_PolylineDlg( module(), getName() );
+  connect( aDlg, SIGNAL( selectionChanged() ), this, SLOT( onEditorSelectionChanged() ) );
+  return aDlg;
+}
+
+bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags,
+                                        QString& theErrorMsg )
+{
+  HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
+
+  int aStudyId = module()->getStudyId();
+  bool aHasDoc = HYDROData_Document::HasDocument(aStudyId);
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
+  if( aDocument.IsNull() )
+    return false;
+
+  Handle(HYDROData_Polyline) aPolylineObj;
+  if( myIsEdit ){
+    aPolylineObj = myEditedObject;
+  }
+  else{
+    aPolylineObj = Handle(HYDROData_Polyline)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
+  }
+
+  if( aPolylineObj.IsNull() )
+    return false;
+
+  QString aPolylineName = aPanel->getPolylineName();
+  aPolylineObj->SetName(aPolylineName);
+  int aDimInt = 3;
+  if( myCurve->getDimension() == CurveCreator::Dim2d )
+    aDimInt = 2;
+  aPolylineObj->setDimension(aDimInt);
+  QList<PolylineSection> aPolylineData;
+  for( int i=0 ; i < myCurve->getNbSections() ; i++ ){
+    PolylineSection aSect;
+    aSect.mySectionName = HYDROGUI_Tool::ToExtString( QString::fromLocal8Bit(myCurve->getSectionName(i).c_str()));
+    aSect.myIsClosed = myCurve->isClosed(i);
+    aSect.myType = PolylineSection::SECTION_POLYLINE;
+    if( myCurve->getType(i) == CurveCreator::BSpline ){
+      aSect.myType = PolylineSection::SECTION_SPLINE;
+    }
+    CurveCreator::Coordinates aCoords = myCurve->getPoints(i);
+    for( int j = 0 ; j < aCoords.size() ; j++ ){
+      aSect.myCoords << aCoords.at(j);
+    }
+    aPolylineData << aSect;
+  }
+  aPolylineObj->setPolylineData(aPolylineData);
+
+  theUpdateFlags = UF_Model;
+  module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), aPolylineObj, true );
+  return true;
+}
+
 void HYDROGUI_PolylineOp::onEditorSelectionChanged()
 {
   HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
@@ -224,25 +195,39 @@ void HYDROGUI_PolylineOp::onEditorSelectionChanged()
   }
 }
 
-void HYDROGUI_PolylineOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
+void HYDROGUI_PolylineOp::displayPreview()
 {
-  closePreview();
-}
+  LightApp_Application* anApp = module()->getApp();
 
-void HYDROGUI_PolylineOp::closePreview()
-{
-  if( myPreviewViewManager )
+  myViewManager =
+    dynamic_cast<OCCViewer_ViewManager*>( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) );
+  if( myViewManager )
   {
-    disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
-                this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
-
-    module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
-    myPreviewViewManager = 0;
+    if( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() )
+    {
+      Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+      if( !aCtx.IsNull() )
+      {
+        myAISCurve = new HYDROGUI_AISCurve( myCurve, aCtx );
+        myAISCurve->Display();
+      }
+    }
   }
+}
 
-  if( myActiveViewManager )
+void HYDROGUI_PolylineOp::erasePreview()
+{
+  if( myViewManager )
   {
-    HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
-    myActiveViewManager = 0;
+    if( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() )
+    {
+      Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+      if( !aCtx.IsNull() && myAISCurve )
+      {
+        myAISCurve->Erase();
+        delete myAISCurve;
+        myAISCurve = 0;
+      }
+    }
   }
 }
index 28667125ae145d5422d481d5cb0bcd7d0474130d..614960dfecb719eeae3c0bc93ac8cc77b5b8c3d7 100755 (executable)
@@ -28,7 +28,6 @@
 #include <HYDROData_Polyline.h>
 
 class OCCViewer_ViewManager;
-class SUIT_ViewManager;
 class CurveCreator_Curve;
 class HYDROGUI_AISCurve;
 
@@ -49,20 +48,15 @@ protected:
 
   virtual bool               processApply( int& theUpdateFlags, QString& theErrorMsg );
 
-  void                       onCreatePreview();
-
 protected slots:
   void                       onEditorSelectionChanged();
 
-  void                       onLastViewClosed( SUIT_ViewManager* );
-
 private:
-  void                       closePreview();
+  void                       displayPreview();
+  void                       erasePreview();
 
 private:
-  SUIT_ViewManager*          myActiveViewManager;
-
-  OCCViewer_ViewManager*     myPreviewViewManager;
+  OCCViewer_ViewManager*     myViewManager;
 
   bool                       myIsEdit;
   Handle(HYDROData_Polyline) myEditedObject;
index 1a69cfb938d258afc3380b5f8b98e099f09ba8dd..4b78aae4c5b7f3b550be93306509c71440716011 100644 (file)
@@ -22,6 +22,9 @@
 
 #include "HYDROGUI_Shape.h"
 
+#include "HYDROGUI_DataObject.h"
+#include "HYDROGUI_Tool.h"
+
 #include <AIS_Drawer.hxx>
 
 #include <BRepBuilderAPI_MakeEdge.hxx>
@@ -34,6 +37,7 @@
 #include <Graphic3d_MaterialAspect.hxx>
 
 #include <HYDROData_Domain.h>
+#include <HYDROData_Image.h>
 #include <HYDROData_Polyline.h>
 
 #include <TopoDS_Wire.hxx>
@@ -46,6 +50,7 @@
 #include <Prs3d_IsoAspect.hxx>
 
 #include <QColor>
+#include <QFile>
 
 HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext,
                                 const Handle(HYDROData_Object)&       theObject )
@@ -67,6 +72,8 @@ HYDROGUI_Shape::~HYDROGUI_Shape()
 
   if ( !myShape.IsNull() )
     myShape.Nullify();
+
+  removeTextureFile();
 }
 
 void HYDROGUI_Shape::display( const bool theIsUpdateViewer )
@@ -117,6 +124,56 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer )
 
       setWire( aPolylineWire, false, false );
     }
+    else if ( myObject->IsKind( STANDARD_TYPE(HYDROData_Image) ) )
+    {
+      Handle(HYDROData_Image) anImageObj =
+        Handle(HYDROData_Image)::DownCast( myObject );
+
+      removeTextureFile();
+
+      QString aTextureFileName = generateTextureFileName( anImageObj );
+
+      QImage anImage = anImageObj->Image();
+      QString aFilePath = anImageObj->GetFilePath();
+      QTransform aTrsf = anImageObj->Trsf();
+
+      int aWidth = anImage.width();
+      int aHeight = anImage.height();
+
+      anImage = anImage.transformed( aTrsf, Qt::SmoothTransformation );
+
+      // temporary optimization, to reduce the saved image size (and the texture quality)
+      QImage anImageToSave = reduceTexture( anImage, 500 );
+      anImageToSave.save( aTextureFileName );
+
+      QPointF aPoint1( 0, 0 );
+      QPointF aPoint2( aWidth, 0 );
+      QPointF aPoint3( aWidth, aHeight );
+      QPointF aPoint4( 0, aHeight );
+
+      aPoint1 = aTrsf.map( aPoint1 );
+      aPoint2 = aTrsf.map( aPoint2 );
+      aPoint3 = aTrsf.map( aPoint3 );
+      aPoint4 = aTrsf.map( aPoint4 );
+
+      QPolygonF aPolygon = QPolygonF() << aPoint1 << aPoint2 << aPoint3 << aPoint4;
+      QRectF aRect = aPolygon.boundingRect();
+
+      gp_Pnt aPnt1( aRect.topLeft().x(), aRect.topLeft().y(), 0 );
+      gp_Pnt aPnt2( aRect.topRight().x(), aRect.topRight().y(), 0 );
+      gp_Pnt aPnt3( aRect.bottomRight().x(), aRect.bottomRight().y(), 0 );
+      gp_Pnt aPnt4( aRect.bottomLeft().x(), aRect.bottomLeft().y(), 0 );
+
+      TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge();
+      TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge( aPnt2, aPnt3 ).Edge();
+      TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge( aPnt3, aPnt4 ).Edge();
+      TopoDS_Edge anEdge4 = BRepBuilderAPI_MakeEdge( aPnt4, aPnt1 ).Edge();
+
+      TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge1, anEdge2, anEdge3, anEdge4 ).Wire();
+
+      setTextureFileName( aTextureFileName, false, false );
+      setFace( aWire, false, false );
+    }
   }
 
   if ( myShape.IsNull() || !isVisible() )
@@ -190,7 +247,7 @@ void HYDROGUI_Shape::setFace( const TopoDS_Face& theFace,
                               const bool         theIsUpdateViewer )
 {
   myTopoShape = theFace;
-  myDisplayMode = AIS_Shaded;
+  myDisplayMode = myTextureFileName.isEmpty() ? AIS_Shaded : AIS_ExactHLR;
 
   buildShape();
   updateShape( theToDisplay, theIsUpdateViewer );
@@ -232,6 +289,19 @@ QColor HYDROGUI_Shape::getHighlightColor() const
   return myHighlightColor;
 }
 
+void HYDROGUI_Shape::setTextureFileName( const QString& theFileName,
+                                         const bool     theToDisplay,
+                                         const bool     theIsUpdateViewer )
+{
+  myTextureFileName = theFileName;
+  updateShape( theToDisplay, theIsUpdateViewer );
+}
+
+QString HYDROGUI_Shape::getTextureFileName() const
+{
+  return myTextureFileName;
+}
+
 void HYDROGUI_Shape::buildShape()
 {
   // Erase previously created shape
@@ -240,7 +310,7 @@ void HYDROGUI_Shape::buildShape()
   if ( myTopoShape.IsNull() )
     return;
 
-  myShape = new AIS_Shape( myTopoShape );
+  myShape = new AIS_TexturedShape( myTopoShape );
 
   if ( !myObject.IsNull() )
     myShape->SetOwner( myObject );
@@ -248,6 +318,14 @@ void HYDROGUI_Shape::buildShape()
   myShape->SetTransparency( 0 );
   myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode );
 
+  QString aTextureFileName = getTextureFileName();
+  if( !aTextureFileName.isEmpty() )
+  {
+    myShape->SetTextureFileName( HYDROGUI_Tool::ToAsciiString( aTextureFileName ) );
+    myShape->SetTextureMapOn();
+    myShape->DisableTextureModulate();
+  }
+
     // Init default params for shape
   const Handle(AIS_Drawer)& anAttributes = myShape->Attributes();
   if ( !anAttributes.IsNull() )
@@ -362,4 +440,50 @@ void HYDROGUI_Shape::colorShapeBorder( const QColor& theColor )
   }
 }
 
+QString HYDROGUI_Shape::generateTextureFileName( const Handle(HYDROData_Object)& theImageObj )
+{
+  QString aResult;
+  if( !theImageObj.IsNull() )
+  {
+    QString aTempDir = HYDROGUI_Tool::GetTempDir( true );
+
+    int aStudyId = HYDROGUI_Tool::GetActiveStudyId();
+    QString aPrefix = QString( "image_%1" ).arg( aStudyId );
 
+    QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theImageObj, false );
+    anEntry.replace( ':', '_' );
+
+    QString anExtension = "bmp";
+
+    aResult = QString( "%1/%2_%3.%4" ).arg( aTempDir, aPrefix, anEntry, anExtension );
+  }
+  return aResult;
+}
+
+void HYDROGUI_Shape::removeTextureFile() const
+{
+  QFile aFile( getTextureFileName() );
+  if( aFile.exists() )
+    aFile.remove();
+}
+
+QImage HYDROGUI_Shape::reduceTexture( const QImage& theImage, const int theSizeLimit )
+{
+  double aSizeLimit = (double)theSizeLimit;
+  double aWidth = (double)theImage.width();
+  double aHeight = (double)theImage.height();
+  if( aWidth > aSizeLimit || aHeight > aSizeLimit )
+  {
+    if( aWidth > aHeight )
+    {
+      aHeight /= ( aWidth / aSizeLimit );
+      aWidth = aSizeLimit;
+    }
+    else
+    {
+      aWidth /= ( aHeight / aSizeLimit );
+      aHeight = aSizeLimit;
+    }
+  }
+  return theImage.scaled( aWidth, aHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation );
+}
index 7e67eb08bdb4e6bbe59ea687300cad77776f6868..6757079efce6467b2722cedd1b44d24ffb7273ef 100644 (file)
 #define HYDROGUI_SHAPE_H
 
 #include <AIS_InteractiveContext.hxx>
-#include <AIS_Shape.hxx>
+#include <AIS_TexturedShape.hxx>
 
 #include <HYDROData_Object.h>
 
 #include <QColor>
+#include <QImage>
 
 #include <TopoDS_Face.hxx>
 #include <TopoDS_Wire.hxx>
@@ -83,6 +84,11 @@ public:
   virtual void               setHighlightColor( const QColor& theColor );
   virtual QColor             getHighlightColor() const;
 
+  virtual void               setTextureFileName( const QString& theFileName,
+                                                 const bool     theToDisplay = true,
+                                                 const bool     theIsUpdateViewer = true );
+  virtual QString            getTextureFileName() const;
+
 protected:
   virtual void               buildShape();
   virtual void               updateShape( const bool theToDisplay      = true,
@@ -93,10 +99,15 @@ private:
   static double              getQuantityColorVal( const int theColorVal );
   void                       colorShapeBorder( const QColor& theColor );
 
+  static QString             generateTextureFileName( const Handle(HYDROData_Object)& theImageObj );
+  void                       removeTextureFile() const;
+
+  static QImage              reduceTexture( const QImage& theImage, const int theSizeLimit );
+
 private:
   Handle(AIS_InteractiveContext) myContext;
   Handle(HYDROData_Object)       myObject;
-  Handle(AIS_Shape)              myShape;
+  Handle(AIS_TexturedShape)      myShape;
 
   bool                           myIsToUpdate;
   bool                           myIsVisible;
@@ -108,6 +119,8 @@ private:
   QColor                         myFillingColor;
   QColor                         myBorderColor;
   QColor                         myHighlightColor;
+
+  QString                        myTextureFileName;
 };
 
 #endif
index 27d50dcb8b481af27295cdfb3449fb4026457744..67abb1566df46c6dc27fb5e626be8b773ac87073 100644 (file)
 
 #include <STD_TabDesktop.h>
 
+#include <SUIT_Session.h>
 #include <SUIT_Study.h>
 #include <SUIT_ViewManager.h>
 #include <SUIT_ViewWindow.h>
 
-#include <QTextCodec>
+#include <QDir>
+#include <QFileInfo>
 #include <QDockWidget>
+#include <QTextCodec>
 
 // Definition of this id allows to use 'latin1' (Qt alias for 'ISO-8859-1')
 // encoding instead of default 'System'
@@ -134,6 +137,54 @@ Handle(TCollection_HExtendedString) HYDROGUI_Tool::ToHExtString( const QString&
   return new TCollection_HExtendedString( ToExtString( src ) );
 }
 
+int HYDROGUI_Tool::GetActiveStudyId()
+{
+  if( SUIT_Session* aSession = SUIT_Session::session() )
+    if( SUIT_Application* anApp = aSession->activeApplication() )
+      if( SUIT_Study* aStudy = anApp->activeStudy() )
+        return aStudy->id();
+  return 0;
+}
+
+QString HYDROGUI_Tool::GetTempDir( const bool theToCreate )
+{
+  QString aRes;
+
+  char* tmpdir = getenv ( "HYDRO_TMP_DIR" );
+  if ( tmpdir )
+  {
+    // try to create folder if it does not exist
+    QFileInfo fi( tmpdir );
+    if ( !fi.exists() && theToCreate )
+    {
+      if ( QDir().mkdir( tmpdir ) )
+        QFile::setPermissions( tmpdir, (QFile::Permissions)0x4FFFF );
+       QFileInfo fi( tmpdir );
+       if ( !fi.exists() || !fi.isWritable() )
+         tmpdir = 0;
+    }
+  }
+  if ( !tmpdir )
+    tmpdir = getenv ( "TEMP" );
+  if ( !tmpdir )
+    tmpdir = getenv ( "TMP" );
+  if ( !tmpdir )
+  {
+#ifdef WNT
+    tmpdir = "C:\\";
+#else
+    tmpdir = "/tmp";
+#endif
+  }
+  aRes = tmpdir;
+  
+  QFileInfo fi( aRes );
+  if ( !fi.exists() || !fi.isWritable() )
+    aRes = QString::null;
+
+  return aRes;
+}
+
 bool HYDROGUI_Tool::IsEqual( const Handle(HYDROData_Object)& theObj1,
                              const Handle(HYDROData_Object)& theObj2 )
 {
index fc60e3b52d45820cd8d3a7de382f1bd77104eb6e..869dd4d23f52afe1ff087675f6bb1f50ebe187b1 100644 (file)
@@ -88,6 +88,19 @@ public:
    */
   static Handle(TCollection_HExtendedString)      ToHExtString( const QString& );
 
+  /**
+   * \brief Get the active study id.
+   * \return active study id
+   */
+  static int                      GetActiveStudyId();
+
+  /**
+   * \brief Get path to the temporary directory.
+   * \param theToCreate flag used to create a directory if it doesn't exist
+   * \return path
+   */
+  static QString                  GetTempDir( const bool theToCreate );
+
   /**
    * \brief Check that the specified objects are equal.
    * \param theObj1 first object
index 3def5370a5f7885b03ef35e16d6b7d239af07cb3..d946766c8e1b781d66f2e304ed05fac26e6279b5 100644 (file)
@@ -228,6 +228,6 @@ bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags,
     module()->setObjectVisible( aViewId, aResult, true );
   }
 
-  theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced;
+  theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;
   return true;
 }
index 0ac92a748e520d4b67df3feab9247d96e22ea902..e0777f2338659f78bb5e8295c8d0959036df322b 100644 (file)
@@ -56,6 +56,6 @@ void HYDROGUI_UpdateImageOp::startOperation()
 
   commitDocOperation();
 
-  module()->update( UF_Model | UF_Viewer | UF_GV_Forced );
+  module()->update( UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced );
   commit();
 }