Salome HOME
size of image is limited by 7000 pixels
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_StreamOp.cxx
index 467d128568a534524d22e0aa2d4c1e0e0af44b2b..89f44d9997b97399b97559e2d379a1deb63634f7 100755 (executable)
@@ -37,6 +37,9 @@
 
 #include <SUIT_MessageBox.h>
 #include <SUIT_Desktop.h>
+#include <QColor>
+#include <QApplication>
+
 
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
@@ -116,32 +119,33 @@ void HYDROGUI_StreamOp::startOperation()
 
       // Hydraulic axis
       Handle(HYDROData_PolylineXY) aHydraulicAxis = myEditedObject->GetHydraulicAxis();
+      
+      TopoDS_Face aPlane;
+      HYDROData_Stream::BuildRefFace( aPlane ) ;
       if ( !aHydraulicAxis.IsNull() )
-      {
         myHydAxis = aHydraulicAxis->GetName();
 
-        TopoDS_Face aPlane;
-        if ( HYDROData_Stream::BuildFace( aHydraulicAxis, aPlane ) )
+      // Stream profiles
+      HYDROData_SequenceOfObjects aStreamProfiles = myEditedObject->GetProfiles();
+      for ( int i = 1, n = aStreamProfiles.Length(); i <= n; ++i )
+      {
+        Handle(HYDROData_Profile) aProfile = 
+          Handle(HYDROData_Profile)::DownCast( aStreamProfiles.Value( i ) );
+        if ( aProfile.IsNull() )
+          continue;
+
+        QString aProfileName = aProfile->GetName();        
+        myProfiles      << aProfileName;
+
+        if (!aHydraulicAxis.IsNull())
         {
-          // Stream profiles
-          HYDROData_SequenceOfObjects aStreamProfiles = myEditedObject->GetProfiles();
-          for ( int i = 1, n = aStreamProfiles.Length(); i <= n; ++i )
-          {
-            Handle(HYDROData_Profile) aProfile = 
-              Handle(HYDROData_Profile)::DownCast( aStreamProfiles.Value( i ) );
-            if ( aProfile.IsNull() )
-              continue;
-
-            QString aProfileName = aProfile->GetName();
-
-            Standard_Real aProfilePar = 0.0;
-            HYDROData_Stream::HasIntersection( aHydraulicAxis, aProfile, aPlane, aProfilePar );
-
-            myProfiles      << aProfileName;
-            myProfileParams << aProfilePar;
-          }
+          Standard_Real aProfilePar = 0.0;
+          HYDROData_Stream::HasIntersection( aHydraulicAxis, aProfile, aPlane, aProfilePar );
+          myProfileParams << aProfilePar;
         }
-      }
+
+      }      
+
     }
   }
 
@@ -192,6 +196,58 @@ HYDROGUI_InputPanel* HYDROGUI_StreamOp::createInputPanel() const
   return aPanel;
 }
 
+void HYDROGUI_StreamOp::apply()
+{
+  QApplication::setOverrideCursor( Qt::WaitCursor );
+
+  startDocOperation();
+
+  int anUpdateFlags = 0;
+  QString anErrorMsg;
+
+  bool aResult = false;
+  QStringList aBrowseObjectsEntries;
+
+  try
+  {
+    aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
+  }
+  catch ( Standard_Failure )
+  {
+    Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
+    anErrorMsg = aFailure->GetMessageString();
+    aResult = false;
+  }
+  catch ( ... )
+  {
+    aResult = false;
+  }
+  
+  QApplication::restoreOverrideCursor();
+
+  if ( aResult )
+  {
+    module()->update( anUpdateFlags );
+    commitDocOperation();
+    commit();
+    browseObjects( aBrowseObjectsEntries );
+  }
+  else
+  {
+    myEditedObject->Remove();
+    module()->setObjectRemoved( myEditedObject );  
+
+    if ( isToAbortOnApply() )
+      abortDocOperation();
+
+    abort();
+    SUIT_MessageBox::critical( module()->getApp()->desktop(),
+                               tr( "CREATE_STREAM_ERROR" ),
+                               anErrorMsg ); 
+
+  } 
+}
+
 bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags,
                                       QString& theErrorMsg,
                                       QStringList& theBrowseObjectsEntries )
@@ -248,10 +304,16 @@ bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags,
     return false;
   }
 
-  // Set the object name
+  bool ToOrder = true;
+
+  if (aHydAxis.IsNull())
+    ToOrder = false;
+
+  myEditedObject->SetProfiles (aRefProfiles, ToOrder) ;
   myEditedObject->SetName( anObjectName );
 
-  myEditedObject->SetHydraulicAxis( aHydAxis );
+  if (!aHydAxis.IsNull())
+    myEditedObject->SetHydraulicAxis( aHydAxis );
   myEditedObject->SetProfiles( aRefProfiles, false );
   myEditedObject->SetDDZ( aPanel->getDDZ() );
   myEditedObject->SetSpatialStep( aPanel->getSpatialStep() );
@@ -323,7 +385,7 @@ void HYDROGUI_StreamOp::createPreview()
     HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) );
 
   HYDROData_SequenceOfObjects aRefProfiles;
-  //std::vector<Handle_HYDROData_Profile> aRefProfiles;
+  //std::vector<Handle(HYDROData_Profile)> aRefProfiles;
   int plen = myProfiles.length();
   for ( int i = 0; i < plen; ++i )
   {
@@ -347,17 +409,36 @@ void HYDROGUI_StreamOp::createPreview()
   HYDROGUI_StreamDlg* aPanel = ::qobject_cast<HYDROGUI_StreamDlg*>( inputPanel() );
   double ddz = aPanel->getDDZ();
   double ss = aPanel->getSpatialStep();
-    
-  HYDROData_DTM::CreateProfilesFromDTM( aRefProfiles, ddz, ss, HYDROData_Bathymetry::AltitudePoints(), Out3dPres, Out2dPres, OutLeftB, OutRightB,
-    OutInlet, OutOutlet, true, true);
-
-  aPrsDef.myInlet = TopoDS::Wire(OutInlet);
-  aPrsDef.myOutlet = TopoDS::Wire(OutOutlet);
-  aPrsDef.myLeftBank = TopoDS::Wire(OutLeftB);
-  aPrsDef.myRightBank = TopoDS::Wire(OutRightB);
-  aPrsDef.myPrs2D = Out2dPres;
+
+  std::set<int> InvInd;
+
+#ifdef _DEBUG
+  const int MAX_POINTS_IN_PREVIEW = 50000;
+#else
+  const int MAX_POINTS_IN_PREVIEW = 500000;
+#endif
+
+  HYDROData_Bathymetry::AltitudePoints points;
+
+  bool ProjStat = true;
+  HYDROData_DTM::CreateProfilesFromDTM( aRefProfiles, ddz, ss, points, Out3dPres, Out2dPres, OutLeftB, OutRightB,
+    OutInlet, OutOutlet, true, true, InvInd, MAX_POINTS_IN_PREVIEW, ProjStat );
+
+  aPanel->clearAllBackgroundColorsForProfileList();
+  for (std::set<int>::const_iterator it = InvInd.begin(); it != InvInd.end(); it++)
+    aPanel->setBackgroundColorForProfileList(*it, QColor(Qt::yellow));
+
+  aPrsDef.myInlet = OutInlet;
+  aPrsDef.myOutlet = OutOutlet;
+  aPrsDef.myLeftBank = OutLeftB;
+  aPrsDef.myRightBank = OutRightB;
+  if (ProjStat)
+    aPrsDef.myPrs2D = Out2dPres;
   aPrsDef.myPrs3D = Out3dPres;
 
+  if (!ProjStat)
+    aPanel->addWarning(tr("STREAM_PROJECTION_FAILED"));
+
   myPreviewPrs->setShape( aPrsDef.myPrs2D );
 }
 
@@ -378,9 +459,7 @@ void HYDROGUI_StreamOp::onAddProfiles()
    // return;
 
   TopoDS_Face aPlane;
-
-  if ( !HYDROData_Stream::BuildFace( aHydAxis, aPlane ) )
-    return;
+  HYDROData_Stream::BuildRefFace( aPlane );
 
   // Get the current profiles list
   QStringList aCurrentProfiles = myProfiles;
@@ -515,15 +594,15 @@ void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis )
 
   // Prepare data for intersection check
   TopoDS_Face aPlane;
-  if ( !HYDROData_Stream::BuildFace( aNewAxis, aPlane ) )
-  {
-    SUIT_MessageBox::critical( module()->getApp()->desktop(), 
-                              tr( "BAD_SELECTED_POLYLINE_TLT" ),
-                              tr( "BAD_SELECTED_POLYLINE_MSG" ).arg( theNewAxis ) );
-    // To restore the old axis
-    updatePanelData();
-    return;
-  }
+  HYDROData_Stream::BuildRefFace( aPlane );
+  //{
+  //  SUIT_MessageBox::critical( module()->getApp()->desktop(), 
+  //                            tr( "BAD_SELECTED_POLYLINE_TLT" ),
+  //                            tr( "BAD_SELECTED_POLYLINE_MSG" ).arg( theNewAxis ) );
+  //  // To restore the old axis
+  //  updatePanelData();
+  //  return;
+  //}
 
   QStringList   aNewProfiles;
   QList<double> aNewProfileParams;