Salome HOME
Fix for the bug #37: Error when import image with format not supported.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationOp.cxx
index e826fb926f4e15ae7ff317c182ecc64c7b156502..54241112d3d13930ca893eb7a8571d82a23b0ed2 100644 (file)
@@ -76,10 +76,35 @@ void HYDROGUI_CalculationOp::startOperation()
     return;
 
   aPanel->reset();
+  QStringList aList;
+  QStringList anEntryList;
+  HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
+  getNamesAndEntries( aSeq, aList, anEntryList );
+  aPanel->setAllGeomObjects( aList, anEntryList );
+
+  // Get all polylines
+  aList.clear();
+  anEntryList.clear();
+  HYDROData_Iterator anIter( doc(), KIND_POLYLINE );
+  Handle(HYDROData_Polyline) aPolylineObj;
+  QString aPolylineName;
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    aPolylineObj = Handle(HYDROData_Polyline)::DownCast( anIter.Current() );
 
-  QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Case" );
+    if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
+    {
+      aPolylineName = aPolylineObj->GetName();
+      if ( !aPolylineName.isEmpty() )
+      {
+        aList.append( aPolylineName );
+        anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
+      }
+    }
+  }
+  aPanel->setPolylineNames( aList, anEntryList );
 
-  QStringList aSelectedObjects;
+  QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Case" );
 
   myEditedObject.Nullify();
   if ( myIsEdit )
@@ -88,7 +113,19 @@ void HYDROGUI_CalculationOp::startOperation()
     if ( !myEditedObject.IsNull() )
     {
       anObjectName = myEditedObject->GetName();
-      updateGeomObjectsList(aPanel);
+      aPolylineObj = myEditedObject->GetBoundaryPolyline();
+      if ( aPolylineObj.IsNull() )
+      {
+        aPanel->setBoundary( QString() );
+      }
+      else
+      {
+        aPolylineName = aPolylineObj->GetName();
+        aPanel->setBoundary( aPolylineName );
+      }
+      aSeq = myEditedObject->GetGeometryObjects();
+      getNamesAndEntries( aSeq, aList, anEntryList );
+      aPanel->includeGeomObjects( aList );
     }
   }
   else
@@ -104,14 +141,14 @@ void HYDROGUI_CalculationOp::startOperation()
   createPreview();
 }
 
-void HYDROGUI_CalculationOp::updateGeomObjectsList( HYDROGUI_CalculationDlg* thePanel ) const
+void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq, 
+                                                QStringList& theNames, QStringList& theEntries ) const
 {
   Handle(HYDROData_Object) anObject;
   Handle(HYDROData_Entity) anEntity;
-  QStringList aList;
-  // Update the list in the dialog
-  HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
-  HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
+  theNames.clear();
+  theEntries.clear();
+  HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
   for ( ; anIter.More(); anIter.Next() )
   {
     anEntity = anIter.Value();
@@ -120,11 +157,11 @@ void HYDROGUI_CalculationOp::updateGeomObjectsList( HYDROGUI_CalculationDlg* the
       anObject = Handle(HYDROData_Object)::DownCast( anEntity );
       if ( !anObject.IsNull() )
       {
-        aList.append( anObject->GetName() );
+        theNames.append( anObject->GetName() );
+        theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anObject ) );
       }
     }
   }
-  thePanel->setSelectedGeomObjects( aList );
 }
 
 void HYDROGUI_CalculationOp::abortOperation()
@@ -160,10 +197,103 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
     SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
   connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
     SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
+  connect( aPanel, SIGNAL( objectSelected( const QString & ) ), 
+    SLOT( onObjectSelected( const QString & ) ) );
+  connect( aPanel, SIGNAL( boundarySelected( const QString & ) ), 
+    SLOT( onBoundarySelected( const QString & ) ) );
 
   return aPanel;
 }
 
+void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
+{
+  // Set the selected boundary polyline to the calculation case
+  Handle(HYDROData_Polyline) anObject;
+  HYDROGUI_Shape* aShape;
+  Handle(AIS_InteractiveContext) aCtx;
+  if ( myPreviewViewManager ) 
+  {
+    if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
+    {
+      aCtx = aViewer->getAISContext();
+    }
+  }
+  // Remove the old boundary from the operation viewer
+  anObject = myEditedObject->GetBoundaryPolyline();
+  if ( !anObject.IsNull() )
+  {
+    module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anObject );
+  }
+
+  if ( theObjName.trimmed().isEmpty() )
+  {
+    // No polyline is selected
+    myEditedObject->RemoveBoundaryPolyline();
+  }
+  else
+  {
+    Handle(HYDROData_Entity) anEntity = 
+      HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINE );
+    if ( !anEntity.IsNull() )
+    {
+      anObject = Handle(HYDROData_Polyline)::DownCast( anEntity );
+      if ( !anObject.IsNull() )
+      {
+        myEditedObject->SetBoundaryPolyline( anObject );
+        if ( !aCtx.IsNull() )
+        {
+          showObject( anEntity, aCtx );
+        }
+      }
+    }
+  }
+}
+
+void HYDROGUI_CalculationOp::onObjectSelected ( const QString & theObjName )
+{
+  // Select the appropriate geometry object shape in the viewer
+  selectionMgr()->clearSelected();
+
+  // Unhighlight all objects except selected
+  HYDROGUI_Shape* aShape;
+  HYDROGUI_Shape* aSelectedShape = 0;
+  Handle(HYDROData_Entity) anEntity;
+  HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
+  HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
+  bool isSelected;
+  QString aName;
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    anEntity = anIter.Value();
+    if ( !anEntity.IsNull() )
+    {
+      aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
+      if ( aShape )
+      {
+        aName = anEntity->GetName();
+        isSelected = ( aName == theObjName );
+        if ( isSelected )
+        {
+          aSelectedShape = aShape;
+        }
+        if ( aShape->isHighlighted() != isSelected )
+        {
+          if ( !isSelected )
+          {
+            aShape->highlight( isSelected );
+            aShape->update();
+          }
+        }
+      }
+    }
+  }
+  if ( aSelectedShape )
+  {
+    aSelectedShape->highlight( true );
+    aSelectedShape->update();
+  }
+}
+
 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
 {
   HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
@@ -275,33 +405,36 @@ void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theBathy
 
 void HYDROGUI_CalculationOp::onAddObjects()
 {
-  // Add geometry objects selected in the module browser to the calculation case
-  Handle(HYDROData_Object) anObject;
-  Handle(HYDROData_Entity) anEntity;
-  QStringList aList;
-  HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
-  for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
+  HYDROGUI_CalculationDlg* aPanel = 
+    ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+  if ( aPanel )
   {
-    anEntity = aSeq.Value( anIndex );
-    if ( !anEntity.IsNull() )
+    // Add geometry objects selected in the module browser to the calculation case
+    Handle(HYDROData_Object) anObject;
+    Handle(HYDROData_Entity) anEntity;
+    QStringList aList;
+    QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
+    for (int i = 0; i < aSelectedList.length(); i++)
     {
-      anObject = Handle(HYDROData_Object)::DownCast( anEntity );
-      if( !anObject.IsNull() )
+      anEntity = HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) );
+      if ( !anEntity.IsNull() )
       {
-        if (myEditedObject->AddGeometryObject( anObject ))
+        anObject = Handle(HYDROData_Object)::DownCast( anEntity );
+        if ( !anObject.IsNull() )
         {
-          aList.append( anObject->GetName() );
+          if (myEditedObject->AddGeometryObject( anObject ))
+          {
+            aList.append( anObject->GetName() );
+          }
         }
       }
     }
+    if ( !aList.isEmpty() )
+    {
+      aPanel->includeGeomObjects( aList );
+      createPreview();
+    }
   }
-  HYDROGUI_CalculationDlg* aPanel = 
-    ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
-  if ( aPanel )
-  {
-    updateGeomObjectsList( aPanel );
-  }
-  createPreview();
 }
 
 void HYDROGUI_CalculationOp::onRemoveObjects()
@@ -327,7 +460,10 @@ void HYDROGUI_CalculationOp::onRemoveObjects()
         }
       }
     }
-    updateGeomObjectsList( aPanel );
+    if ( !aList.isEmpty() )
+    {
+      aPanel->excludeGeomObjects( aList );
+    }
   }
 }
 
@@ -425,27 +561,30 @@ void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
   HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
   HYDROData_SequenceOfObjects aZones;
   Handle(HYDROData_Region) aRegion;
-  if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
+  if ( myPreviewViewManager ) 
   {
-    Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
-    if ( !aCtx.IsNull() )
+    if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
     {
-      for ( ; aRegionsIter.More(); aRegionsIter.Next() )
+      Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+      if ( !aCtx.IsNull() )
       {
-        aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
-        if ( !aRegion.IsNull() )
+        for ( ; aRegionsIter.More(); aRegionsIter.Next() )
         {
-          aZones = aRegion->GetZones();
-          HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
-          for ( ; aZonesIter.More(); aZonesIter.Next() )
+          aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
+          if ( !aRegion.IsNull() )
           {
-            if ( theIsVisible )
+            aZones = aRegion->GetZones();
+            HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
+            for ( ; aZonesIter.More(); aZonesIter.Next() )
             {
-              showObject( aZonesIter.Value(), aCtx );
-            }
-            else
-            {
-              module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZonesIter.Value() );
+              if ( theIsVisible )
+              {
+                showObject( aZonesIter.Value(), aCtx );
+              }
+              else
+              {
+                module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZonesIter.Value() );
+              }
             }
           }
         }
@@ -482,6 +621,9 @@ void HYDROGUI_CalculationOp::createPreview()
     }
   }
 
+  // Get a boundary polyline if any
+  aSeq.Append( myEditedObject->GetBoundaryPolyline() );
+
   module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
 
   if ( !myActiveViewManager )