Salome HOME
Merge branch 'BR_IMPROVEMENTS' of ssh://git.salome-platform.org/modules/hydro into...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ChannelOp.cxx
index 4078af047d4ddd77aeeff284df7a183f56883768..8bf96b1365f9e645b5a224526b93c57f495acdf3 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  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
@@ -6,7 +6,7 @@
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -23,6 +23,7 @@
 #include "HYDROGUI_ChannelOp.h"
 
 #include "HYDROGUI_DataModel.h"
+#include <HYDROGUI_DataObject.h>
 #include "HYDROGUI_ChannelDlg.h"
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_Shape.h"
@@ -65,15 +66,17 @@ void HYDROGUI_ChannelOp::startOperation()
 
   aPanel->reset();
 
-  myEditedObject.Nullify();
+  if ( isApplyAndClose() )
+    myEditedObject.Nullify();
 
   QString aSelectedGuideLine, aSelectedProfile;
 
   QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CHANNEL_NAME" ) );
   if ( myIsEdit )
   {
-    myEditedObject =
-      Handle(HYDROData_Channel)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+    if ( isApplyAndClose() )
+      myEditedObject =
+        Handle(HYDROData_Channel)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
     if ( !myEditedObject.IsNull() )
     {
       anObjectName = myEditedObject->GetName();
@@ -108,7 +111,7 @@ void HYDROGUI_ChannelOp::startOperation()
   }
 
   // collect information about existing profiles
-  QStringList aProfiles = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_PROFILE );
+  QStringList aProfiles = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_PROFILE, true );
 
   aPanel->setObjectName( anObjectName );
 
@@ -143,7 +146,8 @@ HYDROGUI_InputPanel* HYDROGUI_ChannelOp::createInputPanel() const
 }
 
 bool HYDROGUI_ChannelOp::processApply( int& theUpdateFlags,
-                                       QString& theErrorMsg )
+                                       QString& theErrorMsg,
+                                       QStringList& theBrowseObjectsEntries )
 {
   HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
   if ( !aPanel )
@@ -156,7 +160,7 @@ bool HYDROGUI_ChannelOp::processApply( int& theUpdateFlags,
     return false;
   }
 
-  if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
+  if ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
   {
     // check that there are no other objects with the same name in the document
     Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
@@ -203,7 +207,11 @@ bool HYDROGUI_ChannelOp::processApply( int& theUpdateFlags,
   erasePreview();
 
   if( !myIsEdit )
+  {
     module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), myEditedObject, true );
+    QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
+    theBrowseObjectsEntries.append( anEntry );
+  }
 
   module()->setIsToUpdate( myEditedObject );
 
@@ -256,7 +264,20 @@ void HYDROGUI_ChannelOp::onCreatePreview()
     {
       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
       if ( !aCtx.IsNull() )
+      {
         myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
+
+        QColor aFillingColor = getDefaultFillingColor();
+        QColor aBorderColor = getDefaultBorderColor();
+        if ( !myEditedObject.IsNull() )
+        {
+          aFillingColor = myEditedObject->GetFillingColor();
+          aBorderColor = myEditedObject->GetBorderColor();
+        }
+
+        myPreviewPrs->setFillingColor( aFillingColor, false, false );
+        myPreviewPrs->setBorderColor( aBorderColor, false, false );
+      }
     }
   }
 
@@ -270,23 +291,12 @@ void HYDROGUI_ChannelOp::onCreatePreview()
     HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
 
   HYDROData_Channel::PrsDefinition aPrsDef;
-  if ( !HYDROData_Channel::CreatePresentaions( aGuideLine, aProfile, aPrsDef ) )
+  if ( !HYDROData_Channel::CreatePresentations( aGuideLine, aProfile, aPrsDef ) )
   {
     erasePreview();
     return;
   }
 
-  QColor aFillingColor = getDefaultFillingColor();
-  QColor aBorderColor = getDefaultBorderColor();
-  if ( !myEditedObject.IsNull() )
-  {
-    aFillingColor = myEditedObject->GetFillingColor();
-    aBorderColor = myEditedObject->GetBorderColor();
-  }
-
-  myPreviewPrs->setFillingColor( aFillingColor, false, false );
-  myPreviewPrs->setBorderColor( aBorderColor, false, false );
-
   myPreviewPrs->setShape( aPrsDef.myPrs2D );
 }