]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Channel and digue objects creation improved to do not use the transaction during...
authoradv <adv@opencascade.com>
Fri, 21 Mar 2014 10:03:17 +0000 (10:03 +0000)
committeradv <adv@opencascade.com>
Fri, 21 Mar 2014 10:03:17 +0000 (10:03 +0000)
src/HYDROData/HYDROData_Channel.cxx
src/HYDROData/HYDROData_Channel.h
src/HYDROGUI/HYDROGUI_ChannelOp.cxx
src/HYDROGUI/HYDROGUI_ChannelOp.h
src/HYDROGUI/HYDROGUI_DigueOp.cxx
src/HYDROGUI/HYDROGUI_DigueOp.h

index 1f2b6355977729c948959611a4d951ab31d74295..cc8706e5c2695f2a8f658139fa75c2839f1bd04f 100644 (file)
@@ -19,7 +19,6 @@
 #include <TopoDS.hxx>
 #include <TopoDS_Wire.hxx>
 #include <TopoDS_Vertex.hxx>
-#include <TopoDS_Face.hxx>
 
 //#define DEB_CHANNEL 1
 #ifdef DEB_CHANNEL
@@ -85,22 +84,18 @@ TopoDS_Shape HYDROData_Channel::GetShape3D() const
   return getShape3D();
 }
 
-void HYDROData_Channel::Update()
+bool HYDROData_Channel::CreatePresentaions( const Handle(HYDROData_Polyline3D)& theGuideLine,
+                                            const Handle(HYDROData_Profile)&    theProfile,
+                                            PrsDefinition&                      thePrs )
 {
-  HYDROData_ArtificialObject::Update();
-
-  Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
-  Handle(HYDROData_Profile) aProfile = GetProfile();
-  if ( aGuideLine.IsNull() || aProfile.IsNull() )
-    return;
+  if ( theGuideLine.IsNull() || theProfile.IsNull() )
+    return false;
 
   // build 3d shape 
-  TopoDS_Wire aPathWire = TopoDS::Wire(aGuideLine->GetShape3D());
-  if(aPathWire.IsNull())
-    return;
-  TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetShape3D() );
-  if(aProfileWire.IsNull())
-    return;
+  TopoDS_Wire aPathWire = TopoDS::Wire( theGuideLine->GetShape3D() );
+  TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetShape3D() );
+  if ( aPathWire.IsNull() || aProfileWire.IsNull() )
+    return false;
 
 #ifdef DEB_CHANNEL
   BRepTools::Write( aPathWire, "guideline.brep" );
@@ -109,45 +104,57 @@ void HYDROData_Channel::Update()
 
   HYDROData_Canal3dAnd2d aChannelConstructor( aProfileWire, aPathWire );
   if( aChannelConstructor.GetStatus() != 0 )
-    return;
+    return false;
 
   aChannelConstructor.Create3dPresentation();
   aChannelConstructor.Create2dPresentation();
-  SetShape3D( aChannelConstructor.Get3dPresentation() );
-  SetTopShape( aChannelConstructor.Get2dPresentation() );
+  thePrs.myPrs3D = aChannelConstructor.Get3dPresentation();
+  thePrs.myPrs2D = aChannelConstructor.Get2dPresentation();
+
+  thePrs.myLeftBank = aChannelConstructor.GetLeftBank();
+  thePrs.myRightBank = aChannelConstructor.GetRightBank();
+  thePrs.myInlet = aChannelConstructor.GetInlet();
+  thePrs.myOutlet = aChannelConstructor.GetOutlet();
 
 #ifdef DEB_CHANNEL
-  BRepTools::Write( aChannelConstructor.Get2dPresentation(), "channel2d.brep" );
-  BRepTools::Write( aChannelConstructor.Get3dPresentation(), "channel3d.brep" );
+  BRepTools::Write( thePrs.myPrs2D, "channel2d.brep" );
+  BRepTools::Write( thePrs.myPrs3D, "channel3d.brep" );
+  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Top shape edges:", thePrs.myPrs2D, TopAbs_EDGE );
+  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Left bank edges:", thePrs.myLeftBank, TopAbs_EDGE );
+  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Right bank edges:", thePrs.myRightBank, TopAbs_EDGE );
+  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Inlet edges:", thePrs.myInlet, TopAbs_EDGE );
+  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Outlet edges:", thePrs.myOutlet, TopAbs_EDGE );
 #endif
 
-  TopAbs_ShapeEnum aType = GetTopShape().ShapeType();
+  return true;
+}
 
-  // Create groups for channel
-  TopoDS_Wire aLeftBank = aChannelConstructor.GetLeftBank();
-  TopoDS_Wire aRightBank = aChannelConstructor.GetRightBank();
-  TopoDS_Wire anInlet = aChannelConstructor.GetInlet();
-  TopoDS_Wire anOutlet = aChannelConstructor.GetOutlet();
+void HYDROData_Channel::Update()
+{
+  HYDROData_ArtificialObject::Update();
 
-#ifdef DEB_CHANNEL
-  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Top shape edges:", GetTopShape(), TopAbs_EDGE );
-  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Left bank edges:", aLeftBank, TopAbs_EDGE );
-  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Right bank edges:", aRightBank, TopAbs_EDGE );
-  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Inlet edges:", anInlet, TopAbs_EDGE );
-  HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Outlet edges:", anOutlet, TopAbs_EDGE );
-#endif
+  Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
+  Handle(HYDROData_Profile) aProfile = GetProfile();
+
+  PrsDefinition aResultPrs;
+  if ( !CreatePresentaions( aGuideLine, aProfile, aResultPrs ) )
+    return;
+
+  SetShape3D( aResultPrs.myPrs3D );
+  SetTopShape( aResultPrs.myPrs2D );
 
+  // Create groups for channel
   TopTools_SequenceOfShape aLeftBankEdges;
-  HYDROData_ShapesTool::ExploreShapeToShapes( aLeftBank, TopAbs_EDGE, aLeftBankEdges );
+  HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myLeftBank, TopAbs_EDGE, aLeftBankEdges );
 
   TopTools_SequenceOfShape aRightBankEdges;
-  HYDROData_ShapesTool::ExploreShapeToShapes( aRightBank, TopAbs_EDGE, aRightBankEdges );
+  HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myRightBank, TopAbs_EDGE, aRightBankEdges );
 
   TopTools_SequenceOfShape anInletEdges;
-  HYDROData_ShapesTool::ExploreShapeToShapes( anInlet, TopAbs_EDGE, anInletEdges );
+  HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myInlet, TopAbs_EDGE, anInletEdges );
 
   TopTools_SequenceOfShape anOutletEdges;
-  HYDROData_ShapesTool::ExploreShapeToShapes( anOutlet, TopAbs_EDGE, anOutletEdges );
+  HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myOutlet, TopAbs_EDGE, anOutletEdges );
 
   QString aLeftGroupName = GetName() + "_Left_Bank";
 
index b3b4483ce07ec7c867987331734f1e0ac45e358b..f497f36efc489673f1cbd9c9b6a5eee3f360d024 100644 (file)
@@ -4,6 +4,9 @@
 
 #include "HYDROData_ArtificialObject.h"
 
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Wire.hxx>
+
 class Handle(HYDROData_Polyline3D);
 class Handle(HYDROData_Profile);
 class TopTools_SequenceOfShape;
@@ -17,6 +20,18 @@ DEFINE_STANDARD_HANDLE(HYDROData_Channel, HYDROData_ArtificialObject)
  */
 class HYDROData_Channel : public HYDROData_ArtificialObject
 {
+public:
+
+  struct PrsDefinition
+  {
+    TopoDS_Shape myPrs3D;
+    TopoDS_Face  myPrs2D;
+    TopoDS_Wire  myLeftBank;
+    TopoDS_Wire  myRightBank;
+    TopoDS_Wire  myInlet;
+    TopoDS_Wire  myOutlet;
+  };
+
 protected:
   /**
    * Enumeration of tags corresponding to the persistent object parameters.
@@ -29,8 +44,20 @@ protected:
   };
 
 public:
+
   DEFINE_STANDARD_RTTI(HYDROData_Channel);
 
+public:
+
+  /**
+   * Creates the presentation by given guide line and profile.
+   */
+  HYDRODATA_EXPORT static bool CreatePresentaions( const Handle(HYDROData_Polyline3D)& theGuideLine,
+                                                   const Handle(HYDROData_Profile)&    theProfile,
+                                                   PrsDefinition&                      thePrs );
+
+public:
+
   /**
    * Returns the kind of this object. Must be redefined in all objects of known type.
    */
index fe4153171d39ec37f91261cc31417c2488687514..4078af047d4ddd77aeeff284df7a183f56883768 100644 (file)
@@ -59,41 +59,42 @@ void HYDROGUI_ChannelOp::startOperation()
 {
   HYDROGUI_Operation::startOperation();
 
-  // We start operation in the document
-  startDocOperation();
-
   HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
 
   aPanel->blockSignals( true );
 
   aPanel->reset();
 
-  myEditedObject = getObjectToEdit();
+  myEditedObject.Nullify();
 
   QString aSelectedGuideLine, aSelectedProfile;
 
   QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CHANNEL_NAME" ) );
-  if ( myIsEdit && !myEditedObject.IsNull() )
+  if ( myIsEdit )
   {
-    anObjectName = myEditedObject->GetName();
+    myEditedObject =
+      Handle(HYDROData_Channel)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+    if ( !myEditedObject.IsNull() )
+    {
+      anObjectName = myEditedObject->GetName();
 
-    Handle(HYDROData_Polyline3D) aRefGuideLine = myEditedObject->GetGuideLine();
-    if ( !aRefGuideLine.IsNull() )
-      aSelectedGuideLine = aRefGuideLine->GetName();
+      Handle(HYDROData_Polyline3D) aRefGuideLine = myEditedObject->GetGuideLine();
+      if ( !aRefGuideLine.IsNull() )
+        aSelectedGuideLine = aRefGuideLine->GetName();
 
-    Handle(HYDROData_Profile) aRefProfile = myEditedObject->GetProfile();
-    if ( !aRefProfile.IsNull() )
-      aSelectedProfile = aRefProfile->GetName();
+      Handle(HYDROData_Profile) aRefProfile = myEditedObject->GetProfile();
+      if ( !aRefProfile.IsNull() )
+        aSelectedProfile = aRefProfile->GetName();
+    }
   }
 
   // collect information about existing 3d polylines
   QStringList aGuideLines;
-  QStringList anAllGuideLines = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINE );
-  foreach( QString aGuideLine, anAllGuideLines )
+  HYDROData_Iterator aPolylinesIt( doc(), KIND_POLYLINE );
+  for ( ; aPolylinesIt.More(); aPolylinesIt.Next() )
   {
-    Handle( HYDROData_Polyline3D ) aPolyline3d = 
-      Handle( HYDROData_Polyline3D )::DownCast( 
-    HYDROGUI_Tool::FindObjectByName( module(), aGuideLine, KIND_POLYLINE ) );
+    Handle(HYDROData_Polyline3D) aPolyline3d = 
+      Handle(HYDROData_Polyline3D)::DownCast( aPolylinesIt.Current() );
     if( !aPolyline3d.IsNull() )
     {
       TopoDS_Shape aShape = aPolyline3d->GetShape3D();
@@ -101,7 +102,7 @@ void HYDROGUI_ChannelOp::startOperation()
       {
         TopoDS_Wire aWire = TopoDS::Wire( aShape );
         if( !aWire.Closed() )
-          aGuideLines.append( aGuideLine );
+          aGuideLines.append( aPolyline3d->GetName() );
       }
     }
   }
@@ -119,22 +120,18 @@ void HYDROGUI_ChannelOp::startOperation()
 
   aPanel->blockSignals( false );
 
-  onCreatePreview( true );
+  onCreatePreview();
 }
 
-
 void HYDROGUI_ChannelOp::abortOperation()
 {
   erasePreview();
-  abortDocOperation();
-
   HYDROGUI_Operation::abortOperation();
 }
 
 void HYDROGUI_ChannelOp::commitOperation()
 {
   erasePreview();
-
   HYDROGUI_Operation::commitOperation();
 }
 
@@ -170,17 +167,39 @@ bool HYDROGUI_ChannelOp::processApply( int& theUpdateFlags,
     }
   }
 
+  
   if ( myEditedObject.IsNull() )
-    return false;
+    myEditedObject = createNewObject(); // Create new data model object
 
   myEditedObject->SetName( anObjectName );
 
   if ( !myIsEdit )
   {
-    myEditedObject->SetFillingColor( HYDROData_Channel::DefaultFillingColor() );
-    myEditedObject->SetBorderColor( HYDROData_Channel::DefaultBorderColor() );
+    myEditedObject->SetFillingColor( getDefaultFillingColor() );
+    myEditedObject->SetBorderColor( getDefaultBorderColor() );
   }
 
+  QString aGuideLineName = aPanel->getGuideLineName();
+  QString aProfileName = aPanel->getProfileName();
+  if ( aGuideLineName.isEmpty() || aProfileName.isEmpty() )
+  {
+    myEditedObject->RemoveGuideLine();
+    myEditedObject->RemoveProfile();
+  }
+  else
+  {
+    Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast(
+      HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) );
+    myEditedObject->SetGuideLine( aGuideLine );
+
+    Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
+      HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
+    myEditedObject->SetProfile( aProfile );
+  }
+
+  if ( myEditedObject->IsMustBeUpdated() )
+    myEditedObject->Update();
+
   erasePreview();
 
   if( !myIsEdit )
@@ -193,53 +212,42 @@ bool HYDROGUI_ChannelOp::processApply( int& theUpdateFlags,
   return true;
 }
 
-Handle(HYDROData_Channel) HYDROGUI_ChannelOp::getObjectToEdit() const
+Handle(HYDROData_Channel) HYDROGUI_ChannelOp::createNewObject() const
+{
+  return Handle(HYDROData_Channel)::DownCast( doc()->CreateObject( KIND_CHANNEL ) );
+}
+
+QColor HYDROGUI_ChannelOp::getDefaultFillingColor() const
+{
+  return HYDROData_Channel::DefaultFillingColor();
+}
+
+QColor HYDROGUI_ChannelOp::getDefaultBorderColor() const
 {
-  return myIsEdit ? Handle(HYDROData_Channel)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ) :
-                    Handle(HYDROData_Channel)::DownCast( doc()->CreateObject( KIND_CHANNEL ) );
+  return HYDROData_Channel::DefaultBorderColor();
 }
 
-void HYDROGUI_ChannelOp::onCreatePreview( const bool theIsInit )
+void HYDROGUI_ChannelOp::onCreatePreview()
 {
   HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
-  if ( !aPanel || myEditedObject.IsNull() )
+  if ( !aPanel )
     return;
 
   QString aGuideLineName = aPanel->getGuideLineName();
   QString aProfileName = aPanel->getProfileName();
   if ( aGuideLineName.isEmpty() || aProfileName.isEmpty() )
   {
-    if ( !theIsInit )
-    {
-      myEditedObject->RemoveGuideLine();
-      myEditedObject->RemoveProfile();
-      myEditedObject->Update();
-    }
-
     erasePreview();
     return;
   }
 
-  // Update channel data
-  if ( !theIsInit )
-  {
-    Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast(
-      HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) );
-    myEditedObject->SetGuideLine( aGuideLine );
-
-    Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
-      HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
-    myEditedObject->SetProfile( aProfile );
-
-    if ( myEditedObject->IsMustBeUpdated() )
-      myEditedObject->Update();
-  }
-
   LightApp_Application* anApp = module()->getApp();
   
   if ( !getPreviewManager() )
+  {
     setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>( 
                        anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
+  }
 
   OCCViewer_ViewManager* aViewManager = getPreviewManager();
   if ( aViewManager && !myPreviewPrs )
@@ -248,14 +256,38 @@ void HYDROGUI_ChannelOp::onCreatePreview( const bool theIsInit )
     {
       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
       if ( !aCtx.IsNull() )
-        myPreviewPrs = new HYDROGUI_Shape( aCtx, myEditedObject, getPreviewZLayer() );
+        myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
     }
   }
 
   if ( !aViewManager || !myPreviewPrs )
     return;
 
-  myPreviewPrs->update( true );
+  Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast(
+    HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) );
+
+  Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
+    HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
+
+  HYDROData_Channel::PrsDefinition aPrsDef;
+  if ( !HYDROData_Channel::CreatePresentaions( 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 );
 }
 
 void HYDROGUI_ChannelOp::erasePreview()
index eb15b4e861515b35970a17934079f49412935369..798d7a89ae747e3aa981f3111758b83421a87c8b 100644 (file)
@@ -49,14 +49,18 @@ protected:
   virtual bool               processApply( int& theUpdateFlags, QString& theErrorMsg );
 
 protected slots:
-  virtual void               onCreatePreview( const bool theIsInit = false );
+  virtual void               onCreatePreview();
 
 protected:
   virtual void               erasePreview();
 
-  virtual Handle(HYDROData_Channel) getObjectToEdit() const;
+  virtual Handle(HYDROData_Channel) createNewObject() const;
 
-  virtual HYDROGUI_Shape*   getPreviewShape() const { return myPreviewPrs; };
+  virtual QColor             getDefaultFillingColor() const;
+
+  virtual QColor             getDefaultBorderColor() const;
+
+  virtual HYDROGUI_Shape*    getPreviewShape() const { return myPreviewPrs; };
 
 protected:
   bool                       myIsEdit;
index 0d8c6073b778916acc6e38ba394587abee17b90e..f16708f3da20d4839370f3f66a217c84bc1d363b 100644 (file)
@@ -75,8 +75,17 @@ HYDROGUI_InputPanel* HYDROGUI_DigueOp::createInputPanel() const
   return aPanel;
 }
 
-Handle(HYDROData_Channel) HYDROGUI_DigueOp::getObjectToEdit() const
+Handle(HYDROData_Channel) HYDROGUI_DigueOp::createNewObject() const
 {
-  return myIsEdit ? Handle(HYDROData_Digue)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ) :
-                    Handle(HYDROData_Digue)::DownCast( doc()->CreateObject( KIND_DIGUE ) );
+  return Handle(HYDROData_Digue)::DownCast( doc()->CreateObject( KIND_DIGUE ) );
+}
+
+QColor HYDROGUI_DigueOp::getDefaultFillingColor() const
+{
+  return HYDROData_Digue::DefaultFillingColor();
+}
+
+QColor HYDROGUI_DigueOp::getDefaultBorderColor() const
+{
+  return HYDROData_Digue::DefaultBorderColor();
 }
index 429baf62c57b0e8ce64c881be8afa0a0cfff87b5..782626a789388e002eb18db4ff45a1946115142a 100644 (file)
@@ -43,7 +43,11 @@ protected:
 
 protected:
 
-  virtual Handle(HYDROData_Channel) getObjectToEdit() const;
+  virtual Handle(HYDROData_Channel) createNewObject() const;
+
+  virtual QColor               getDefaultFillingColor() const;
+
+  virtual QColor               getDefaultBorderColor() const;
 
 private: