Salome HOME
HYDRO bug 17: add HYDRO version in About dialog.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_PolylineOp.cxx
index 3e9d21a69e74db413b28bcc0a2b0dae200541f9b..45383c5c58ba150577f74f8a57576be51df0de0e 100755 (executable)
 #include "HYDROGUI_PolylineOp.h"
 #include "HYDROGUI_PolylineDlg.h"
 #include "HYDROGUI_Tool.h"
+#include "CurveCreator.hxx"
+#include "CurveCreator_Curve.hxx"
+#include "CurveCreator_CurveEditor.hxx"
+#include "HYDROGUI_AISCurve.h"
 
 #include <HYDROData_Document.h>
 #include <HYDROData_Polyline.h>
 #include <CurveCreator_CurveEditor.hxx>
 
 #include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
 #include <LightApp_UpdateFlags.h>
 
+#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewModel.h>
+
+#include <OCCViewer_AISSelector.h>
 
 HYDROGUI_PolylineOp::HYDROGUI_PolylineOp( HYDROGUI_Module* theModule, bool theIsEdit )
-: HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myCurve(NULL)
+: HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myCurve(NULL), 
+  myActiveViewManager(NULL), myPreviewViewManager(NULL), myAISCurve(NULL)
 {
   setName( theIsEdit ? tr( "EDIT_POLYLINE" ) : tr( "CREATE_POLYLINE" ) );
 }
@@ -45,7 +55,9 @@ HYDROGUI_PolylineOp::~HYDROGUI_PolylineOp()
 
 HYDROGUI_InputPanel* HYDROGUI_PolylineOp::createInputPanel() const
 {
-  return new HYDROGUI_PolylineDlg( module(), getName() );
+  HYDROGUI_PolylineDlg* aDlg = new HYDROGUI_PolylineDlg( module(), getName() );
+  connect( aDlg ,SIGNAL( selectionChanged() ), this, SLOT( onEditorSelectionChanged() ) );
+  return aDlg;
 }
 
 bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags,
@@ -94,10 +106,33 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags,
   aPolylineObj->setPolylineData(aPolylineData);
 
   theUpdateFlags = UF_Model;
-  aPolylineObj->SetVisibility( true );
+  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 )
+  {
+    anApp->selectionMgr()->setEnabled(false);
+    myPreviewViewManager->setTitle( tr( "CREATE_CURVE" ) );
+    OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
+    aViewer->enableSelection(true);
+    aViewer->enableMultiselection(true);
+    Handle_AIS_InteractiveContext aCtx = aViewer->getAISContext();
+
+    myAISCurve = new HYDROGUI_AISCurve(myCurve, aCtx);
+
+    myAISCurve->Display();
+  }
+}
+
 void HYDROGUI_PolylineOp::startOperation()
 {
   CurveCreator_Curve* anOldCurve = myCurve;
@@ -142,6 +177,27 @@ void HYDROGUI_PolylineOp::startOperation()
     aPanel->setPolylineName(aNewName);
   }
   aPanel->setCurve(myCurve);
+  if( myAISCurve )
+    myAISCurve->setCurve(myCurve);
   if( anOldCurve )
     delete anOldCurve;
+  onCreatePreview();
+}
+
+void HYDROGUI_PolylineOp::onEditorSelectionChanged()
+{
+  HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
+  if( !aPanel )
+    return;
+  if( !myCurve )
+    return;
+  if( !myAISCurve )
+    return;
+  QList<int> aSelSections = aPanel->getSelectedSections();
+  for( int i = 0 ; i < myCurve->getNbSections() ; i++ ){
+    bool aIsHl = false;
+    if( aSelSections.contains(i) ){
+      myAISCurve->highlightSection(i, aIsHl);
+    }
+  }
 }