]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
merge BR_hydro_v_1_0_4 on BR_quadtree
authorPaul RASCLE <paul.rascle@edf.fr>
Wed, 7 Jan 2015 19:18:22 +0000 (19:18 +0000)
committerPaul RASCLE <paul.rascle@edf.fr>
Wed, 7 Jan 2015 19:18:22 +0000 (19:18 +0000)
38 files changed:
src/HYDROData/CMakeLists.txt
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_CalculationCase.h
src/HYDROData/HYDROData_Document.cxx
src/HYDROData/HYDROData_Entity.cxx
src/HYDROData/HYDROData_Entity.h
src/HYDROData/HYDROData_Obstacle.cxx
src/HYDROData/HYDROData_Obstacle.h
src/HYDROData/HYDROData_PriorityQueue.cxx [new file with mode: 0644]
src/HYDROData/HYDROData_PriorityQueue.h [new file with mode: 0644]
src/HYDROData/HYDROData_Region.cxx
src/HYDROData/HYDROData_Region.h
src/HYDROData/HYDROData_SplitToZonesTool.cxx
src/HYDROData/HYDROData_SplitToZonesTool.h
src/HYDROData/HYDROData_Warning.h [new file with mode: 0644]
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_CalculationDlg.cxx
src/HYDROGUI/HYDROGUI_CalculationDlg.h
src/HYDROGUI/HYDROGUI_CalculationOp.cxx
src/HYDROGUI/HYDROGUI_CalculationOp.h
src/HYDROGUI/HYDROGUI_DataBrowser.cxx
src/HYDROGUI/HYDROGUI_DataBrowser.h
src/HYDROGUI/HYDROGUI_DataModel.cxx
src/HYDROGUI/HYDROGUI_DataObject.cxx
src/HYDROGUI/HYDROGUI_ExportCalculationOp.cxx
src/HYDROGUI/HYDROGUI_ListModel.cxx
src/HYDROGUI/HYDROGUI_ListModel.h
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx
src/HYDROGUI/HYDROGUI_OrderedListWidget.h
src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_PriorityTableModel.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_PriorityWidget.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_PriorityWidget.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_Wizard.cxx
src/HYDROGUI/HYDROGUI_Wizard.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts
src/HYDROPy/HYDROData_CalculationCase.sip

index 06b6ba091b1d1f2bf6258457d11e8887c27e1b9d..53fb279f91e44dcf13c097f2fda2be57b0ed0ce0 100644 (file)
@@ -30,6 +30,7 @@ set(PROJECT_HEADERS
     HYDROData_Pipes.h
     HYDROData_PolylineXY.h
     HYDROData_Polyline3D.h
+    HYDROData_PriorityQueue.h
     HYDROData_Profile.h
     HYDROData_ProfileUZ.h
     HYDROData_Projection.h
@@ -44,6 +45,7 @@ set(PROJECT_HEADERS
     HYDROData_Tool.h
     HYDROData_Transform.h
     HYDROData_VisualState.h
+    HYDROData_Warning.h
     HYDROData_Zone.h
     HYDROData_Tree.hxx
     HYDROData_Quadtree.hxx
@@ -80,6 +82,7 @@ set(PROJECT_SOURCES
     HYDROData_Pipes.cxx
     HYDROData_PolylineXY.cxx
     HYDROData_Polyline3D.cxx
+    HYDROData_PriorityQueue.cxx
     HYDROData_Profile.cxx
     HYDROData_ProfileUZ.cxx
     HYDROData_Projection.cxx
index dcc662d6d9544831c50e18c04f25e19864ab8a13..e97ae06c8676590273b58410af3b84e53f16480c 100644 (file)
@@ -8,11 +8,9 @@
 #include "HYDROData_Iterator.h"
 #include "HYDROData_NaturalObject.h"
 #include "HYDROData_PolylineXY.h"
-#include "HYDROData_SplitToZonesTool.h"
 #include "HYDROData_SplittedShapesGroup.h"
 #include "HYDROData_Region.h"
 #include "HYDROData_Tool.h"
-#include "HYDROData_Zone.h"
 
 #include <GEOMBase.h>
 
@@ -33,6 +31,7 @@
 #include <TopExp.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <TDataStd_Integer.hxx>
 
 //#define  DEB_CALCULATION 1
 #ifdef DEB_CALCULATION
@@ -49,6 +48,9 @@
 
 #define EXPORT_NAME "HYDRO_" + GetName()
 
+#include <SALOME_NamingService.hxx>
+#include <SALOME_LifeCycleCORBA.hxx>
+
 #define _DEVDEBUG_
 #include "HYDRO_trace.hxx"
 
@@ -114,9 +116,14 @@ void HYDROData_CalculationCase::SetName( const QString& theName )
 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
 {
   QStringList aResList = dumpObjectCreation( theTreatedObjects );
+  aResList.prepend( "# Calculation case" );
 
   QString aCalculName = GetObjPyName();
 
+  AssignmentMode aMode = GetAssignmentMode();
+  QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
+  aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
+
   HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
   HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
   for ( ; anIter.More(); anIter.Next() )
@@ -149,44 +156,96 @@ QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTre
 
     aResList << QString( "%1.AddGeometryGroup( %2 );" ).arg( aCalculName ).arg( aGroupName );
   }
-  aResList << QString( "" );
 
   Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
   setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
-  aResList << QString( "" );
 
-  aResList << QString( "%1.Update();" ).arg( aCalculName );
+  if( aMode==AUTOMATIC )
+    DumpRulesToPython( aCalculName, aResList );
+
   aResList << QString( "" );
+  aResList << "# Start the algorithm of the partition and assignment";
+  aResList << QString( "%1.Update();" ).arg( aCalculName );
 
-  // Now we restore the regions and zones order
-  HYDROData_SequenceOfObjects aRegions = GetRegions();
-  anIter.Init( aRegions );
-  for ( ; anIter.More(); anIter.Next() )
+  if( aMode==MANUAL )
   {
-    Handle(HYDROData_Region) aRegion =
-      Handle(HYDROData_Region)::DownCast( anIter.Value() );
-    if ( aRegion.IsNull() )
-      continue;
-
-    QString aRegionName = aRegion->GetName();
-
-    HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
-    HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
-    for ( ; aZonesIter.More(); aZonesIter.Next() )
+    // Now we restore the regions and zones order
+    HYDROData_SequenceOfObjects aRegions = GetRegions();
+    anIter.Init( aRegions );
+    for ( ; anIter.More(); anIter.Next() )
     {
-      Handle(HYDROData_Zone) aRegZone =
-        Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
-      if ( aRegZone.IsNull() )
+      Handle(HYDROData_Region) aRegion =
+        Handle(HYDROData_Region)::DownCast( anIter.Value() );
+      if ( aRegion.IsNull() )
         continue;
 
-      // TODO
+      theTreatedObjects.insert( aRegion->GetName(), aRegion );
+      QStringList aRegDump = aRegion->DumpToPython( theTreatedObjects );
+      aResList << aRegDump;
     }
   }
+
+  // Export calculation case
   aResList << QString( "" );
+  aResList << "# Export of the calculation case";
+  QString aStudyName = "theStudy";
+  QString anEntryVar = aCalculName + "_entry";
+  aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
+
+  // Get geometry object and print debug information
+  aResList << "";
+  aResList << "# Get geometry shape and print debug information";
+  aResList << "import GEOM";
+  aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
+  QString aGeomShapeName = aCalculName + "_geom";
+  aResList << QString( "%1 = salome.IDToObject( str( %2 ) )" ).arg( aGeomShapeName ).arg( anEntryVar );
+  aResList << QString( "print \"Geom shape:\", %1" ).arg( aGeomShapeName );
+  aResList << QString( "print \"Geom shape name:\", %1.GetName()" ).arg( aGeomShapeName );
+
+  DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
 
+  aResList << QString( "" );
   return aResList;
 }
 
+void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
+                                                   const QString& theStudyName,
+                                                   const QString& theGeomShapeName,
+                                                   const QString& theMeshName ) const
+{
+  theResList << "";
+  theResList << "# Meshing";
+  theResList << "import SMESH, SALOMEDS";
+  theResList << "from salome.smesh import smeshBuilder";
+  theResList << "from salome.geom import geomBuilder";
+
+  theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
+  theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
+  theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
+  theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
+  theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
+  theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
+  theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
+
+  theResList << "";
+  theResList << "# Set names of Mesh objects";
+  theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
+  theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
+  theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
+  theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
+  theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
+
+  theResList << "";
+  theResList << "# Greate SMESH groups";
+  theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
+  theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
+  theResList << QString( "for group in geom_groups:" );
+  theResList << QString( "    smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
+                .arg( theMeshName );
+  theResList << QString( "    smesh.SetName(smesh_group, group.GetName())" );
+  theResList << QString( "    print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
+}
+
 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
 {
   HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
@@ -204,6 +263,7 @@ HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects()
 void HYDROData_CalculationCase::Update()
 {
   HYDROData_Entity::Update();
+  SetWarning();
 
   // At first we remove previously created objects
   RemoveRegions();
@@ -220,84 +280,165 @@ void HYDROData_CalculationCase::Update()
 
   HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
 
-  HYDROData_SplitToZonesTool::SplitDataList aSplitedObjects =
+  HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
     HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
-  if ( aSplitedObjects.isEmpty() )
+  if ( aSplitObjects.isEmpty() )
     return;
 
-  QString aRegsPref = CALCULATION_REGIONS_PREF;
-  QString aZonesPref = CALCULATION_ZONES_PREF;
+  HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
 
-  QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
+  HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
+  while( anIter.hasNext() )
+  {
+    const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
+    if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
+      aZonesList.append( aSplitData );
+    else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
+      anEdgesList.append( aSplitData );
+  }
 
+  switch( GetAssignmentMode() )
+  {
+  case MANUAL:
+    CreateRegionsDef( aDocument, aZonesList );
+    break;
+  case AUTOMATIC:
+    CreateRegionsAuto( aDocument, aZonesList );
+    break;
+  }
+  CreateEdgeGroupsDef( aDocument, anEdgesList );
+}
+
+void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
+                                                  const HYDROData_SplitToZonesTool::SplitDataList& theZones )
+{
   // Create result regions for case, by default one zone for one region
-  HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedObjects );
+  QString aRegsPref = CALCULATION_REGIONS_PREF;
+  QString aZonesPref = CALCULATION_ZONES_PREF;
+
+  HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
   while( anIter.hasNext() )
   {
     const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
+    // Create new region
+    Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
 
-    if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
-    {
-      // Create new region
-      Handle(HYDROData_Region) aRegion = addNewRegion();
-
-      QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
-      aRegion->SetName( aRegionName );
+    // Add the zone for region
+    Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
+  }
+}
 
-      // Add the zone for region
-      Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
+void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
+                                                   const HYDROData_SplitToZonesTool::SplitDataList& theZones )
+{
+  QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
+  QMap<QString, QString> aRegionNameToObjNameMap;
+  QString aZonesPref = CALCULATION_ZONES_PREF;
+  HYDROData_PriorityQueue aPr( this );
 
-      QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref );
-      aRegionZone->SetName( aZoneName );
+  // 1. First we create a default region for each object included into the calculation case
+  HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
+  for( int i=aGeomObjects.Lower(), n=aGeomObjects.Upper(); i<=n; i++ )
+  {
+    Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( aGeomObjects.Value( i ) );
+    if( anObj.IsNull() )
+      continue;
+    QString anObjName = anObj->GetName();
+    QString aRegName = anObjName + "_reg";
+    Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
+    aRegionsMap.insert( anObjName, aRegion );
+    aRegionNameToObjNameMap.insert( aRegName, anObjName );
+  }
 
-      aRegionZone->SetShape( aSplitData.Face() );
+  // 2. Now for each zone it is necessary to determine the most priority object
+  //    and assign to zone to corresponding region
+  HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
+  while( anIter.hasNext() )
+  {
+    const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
+    HYDROData_Zone::MergeAltitudesType aMergeType;
+    Handle(HYDROData_Object) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
+    if( aRegObj.IsNull() )
+      continue;
+    Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
+    if( aRegion.IsNull() )
+      continue;
+    Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
 
-      // Add the reference object for zone
-      for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
-      {
-        const QString& anObjName = aSplitData.ObjectNames.at( i );
-        
-        Handle(HYDROData_Object) aRefObject = 
-          Handle(HYDROData_Object)::DownCast( aDocument->FindObjectByName( anObjName ) );
-        if ( aRefObject.IsNull() )
-          continue;
+    if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
+    {
+      qDebug( "Error in algorithm: unresolved conflicts" );
+    }
 
-        aRegionZone->AddGeometryObject( aRefObject );
-      }
+    switch( aMergeType )
+    {
+    case HYDROData_Zone::Merge_ZMIN:
+    case HYDROData_Zone::Merge_ZMAX:
+      aRegionZone->SetMergeType( aMergeType );
+      break;
+    case HYDROData_Zone::Merge_Object:
+      aRegionZone->SetMergeType( aMergeType );
+      aRegionZone->RemoveMergeAltitude();
+      aRegionZone->SetMergeAltitude( aRegObj->GetAltitudeObject() );
+      break;
     }
-    else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
+  }
+
+  QStringList anObjectsWithEmptyRegions;
+  QMap<QString, Handle(HYDROData_Region)>::const_iterator
+    anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
+  for( ; anIt!=aLast; anIt++ )
+  {
+    Handle(HYDROData_Region) aRegion = anIt.value();
+    if( aRegion->GetZones().IsEmpty() )
     {
-      // Create new edges group
-      if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
-        continue;
+      QString aRegName = aRegion->GetName();
+      QString anObjName = aRegionNameToObjNameMap[aRegName];
+      anObjectsWithEmptyRegions.append( anObjName );
+    }
+  }
+  
+  if( !anObjectsWithEmptyRegions.empty() )
+  {
+    QString aData = anObjectsWithEmptyRegions.join( ", " );
+    SetWarning( WARN_EMPTY_REGIONS, aData );
+  }
+}
 
-      QString anObjName = aSplitData.ObjectNames.first();
-      if ( anObjName.isEmpty() )
-        continue;
+void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
+                                                     const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
+{
+  QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
+
+  HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
+  while( anIter.hasNext() )
+  {
+    const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
+    // Create new edges group
+    if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
+      continue;
+
+    QString anObjName = aSplitData.ObjectNames.first();
+    if ( anObjName.isEmpty() )
+      continue;
 #ifdef DEB_CALCULATION
-      QString aStr = aSplitData.ObjectNames.join(" "); 
+    QString aStr = aSplitData.ObjectNames.join(" "); 
          cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl; 
 #endif
-      Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
-      if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
-      {
-        aSplittedGroup = addNewSplittedGroup();
-
-        QString aCalcGroupName = CALCULATION_GROUPS_PREF + anObjName;
-        aSplittedGroup->SetName( aCalcGroupName );
-
-        aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
-      }
-      else
-      {
-        aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
-      }
-
-      if ( aSplittedGroup.IsNull() )
-        continue;
-
-      aSplittedGroup->AddShape( aSplitData.Shape );
+    Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
+    if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
+    {
+      aSplittedGroup = addNewSplittedGroup( CALCULATION_GROUPS_PREF + anObjName );
+      aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
     }
+    else
+    {
+      aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
+    }
+    if ( aSplittedGroup.IsNull() )
+      continue;
+
+    aSplittedGroup->AddShape( aSplitData.Shape );
   }
 }
 
@@ -409,20 +550,11 @@ void HYDROData_CalculationCase::RemoveBoundaryPolyline()
 
 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
 {
-  Handle(HYDROData_Region) aNewRegion = addNewRegion();
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
   if ( aNewRegion.IsNull() )
     return aNewRegion;
 
-  // Generate new name for new region
-  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
-  if ( !aDocument.IsNull() )
-  {
-    QString aRegsPref = CALCULATION_REGIONS_PREF;
-
-    QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
-    aNewRegion->SetName( aNewRegionName );
-  }
-
   aNewRegion->AddZone( theZone );
 
   return aNewRegion;
@@ -430,6 +562,8 @@ Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(H
 
 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
 {
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+
   if ( theRegion.IsNull() )
     return false;
   
@@ -441,7 +575,7 @@ bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRe
     Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
   if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
   {
-    Handle(HYDROData_Region) aNewRegion = addNewRegion();
+    Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
     theRegion->CopyTo( aNewRegion );
 
     aFatherCalc->RemoveRegion( theRegion );
@@ -752,18 +886,24 @@ HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPoi
   return aRes;
 }
 
-Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion()
+Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
+                                                                  const QString& thePrefixOrName,
+                                                                  bool isPrefix )
 {
   TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
+  int aTag = aNewLab.Tag();
 
   Handle(HYDROData_Region) aNewRegion =
     Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
   AddRegion( aNewRegion );
 
+  QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
+  aNewRegion->SetName( aRegionName );
+
   return aNewRegion;
 }
 
-Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup()
+Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup( const QString& theName )
 {
   TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
 
@@ -772,11 +912,33 @@ Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedG
       HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
   AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
 
+  aNewGroup->SetName( theName );
+
   return aNewGroup;
 }
 
+QString HYDROData_CalculationCase::Export( int theStudyId ) const
+{
+  int argc = 0;
+  char** argv = 0;
+  CORBA::ORB_var anORB = CORBA::ORB_init( argc, argv, "omniORB4"/*CORBA::ORB_ID*/ );
+  SALOME_NamingService aNameService( anORB );
+  SALOME_LifeCycleCORBA aLCC( &aNameService );
+  Engines::EngineComponent_var aComponent = aLCC.FindOrLoad_Component( "FactoryServer", "GEOM" );
+  GEOM::GEOM_Gen_var aGEOMEngine = GEOM::GEOM_Gen::_narrow( aComponent );
+  
+  CORBA::Object_var aSMObject = aNameService.Resolve("/myStudyManager");
+  SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
+  SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID( theStudyId );
+
+  QString aGeomObjEntry;
+  bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry );
+  return isOK ? aGeomObjEntry : QString();
+}
+
 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var  theGeomEngine,
-                                        SALOMEDS::Study_ptr theStudy ) const
+                                        SALOMEDS::Study_ptr theStudy,
+                                        QString& theGeomObjEntry ) const
 {
   HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
 
@@ -815,13 +977,14 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var  theGeomEngine,
     aFaces.Append( aRegionShape );
   }
 
-  return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs );
+  return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );
 }
 
 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var                            theGeomEngine,
                                         SALOMEDS::Study_ptr                           theStudy,
                                         const TopTools_ListOfShape&                   theFaces,
-                                        const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs ) const
+                                        const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
+                                        QString& theGeomObjEntry ) const
 {
   // Sew faces
   BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
@@ -875,7 +1038,7 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var
   // Publish the sewed shape
   QString aName = EXPORT_NAME;
   GEOM::GEOM_Object_ptr aMainShape = 
-    publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName );
+    publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
 
   if ( aMainShape->_is_nil() )  
     return false;
@@ -974,8 +1137,10 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var
 
 GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM( 
   GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
-  const TopoDS_Shape& theShape, const QString& theName ) const
+  const TopoDS_Shape& theShape, const QString& theName,
+  QString& theGeomObjEntry ) const
 {
+  theGeomObjEntry = "";
   GEOM::GEOM_Object_var aGeomObj;
 
   if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
@@ -1009,7 +1174,86 @@ GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
     if ( aResultSO->_is_nil() ) {
       aGeomObj = GEOM::GEOM_Object::_nil();
     }
+    else
+      theGeomObjEntry = aResultSO->GetID();
   }
 
   return aGeomObj._retn();
- }
+}
+
+void HYDROData_CalculationCase::ClearRules( const bool theIsSetToUpdate )
+{
+  TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
+  HYDROData_PriorityQueue::ClearRules( aRulesLab );
+
+  // Indicate model of the need to update splitting
+  if ( theIsSetToUpdate ) {
+    SetToUpdate( true );
+  }
+}
+
+void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Object)&    theObject1,
+                                         HYDROData_PriorityType             thePriority,
+                                         const Handle(HYDROData_Object)&    theObject2,
+                                         HYDROData_Zone::MergeAltitudesType theMergeType )
+{
+  TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
+  HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
+
+  // Indicate model of the need to update splitting
+  SetToUpdate( true );
+}
+
+QString HYDROData_CalculationCase::DumpRules() const
+{
+  TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
+  return HYDROData_PriorityQueue::DumpRules( aRulesLab );
+}
+
+void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
+{
+  TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
+  TDataStd_Integer::Set( aModeLab, ( int ) theMode );
+
+  // Indicate model of the need to update splitting
+  SetToUpdate( true );
+}
+
+HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
+{
+  Handle(TDataStd_Integer) aModeAttr;
+  bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
+  if( isOK )
+    return ( AssignmentMode ) aModeAttr->Get();
+  else
+    return MANUAL;
+}
+
+void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
+                                                   QStringList& theScript ) const
+{
+  TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
+  HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
+}
+
+HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
+{
+  return myLastWarning;
+}
+
+void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
+{
+  myLastWarning.Type = theType;
+  myLastWarning.Data = theData;
+}
+
+bool HYDROData_CalculationCase::GetRule( int theIndex, 
+                                         Handle(HYDROData_Object)&           theObject1,
+                                         HYDROData_PriorityType&             thePriority,
+                                         Handle(HYDROData_Object)&           theObject2,
+                                         HYDROData_Zone::MergeAltitudesType& theMergeType ) const
+{
+  TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
+  return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
+    theObject1, thePriority, theObject2, theMergeType );
+}
index 3629a7dd82c23cd2f9d539d12f5636294362e59c..4f0ed90f7ed4aa8b15d77e4a788a0145b6ab38f4 100644 (file)
@@ -4,6 +4,10 @@
 #define HYDROData_CalculationCase_HeaderFile
 
 #include <HYDROData_ShapesGroup.h>
+#include <HYDROData_SplitToZonesTool.h>
+#include <HYDROData_PriorityQueue.h>
+#include <HYDROData_Zone.h>
+#include <HYDROData_Warning.h>
 
 // IDL includes
 #include <SALOMEconfig.h>
@@ -21,6 +25,7 @@ class Handle(HYDROData_Zone);
 class Handle(HYDROData_PolylineXY);
 class Handle(HYDROData_ShapesGroup);
 class Handle(HYDROData_SplittedShapesGroup);
+class Handle(HYDROData_Document);
 
 DEFINE_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
 
@@ -40,7 +45,13 @@ public:
     POINT_ON    ///< point is on the edge of zone face
   };
 
-protected:
+  enum AssignmentMode
+  {
+    MANUAL = 0,
+    AUTOMATIC,
+  };
+
+public:
 
   /**
    * Enumeration of tags corresponding to the persistent object parameters.
@@ -54,6 +65,8 @@ protected:
     DataTag_Polyline,         ///< reference boundary polyline
     DataTag_GeometryGroup,    ///< reference geometry groups
     DataTag_SplittedGroups,   ///< reference splitted groups
+    DataTag_CustomRules,      ///< custom rules
+    DataTag_AssignmentMode,   ///< assignment mode
   };
 
 public:
@@ -194,6 +207,12 @@ public:
    */
   HYDRODATA_EXPORT virtual void RemoveSplittedGroups();
 
+  /**
+   * Exports the calculation case data (shell and groups) to GEOM module.
+   * \param theStudyId the id of the study where the GEOM module should be used for export
+   * \return the entry of the GEOM object (empty string in the case of error)
+   */
+  HYDRODATA_EXPORT virtual QString Export( int theStudyId ) const;
 
   /**
    * Exports the calculation case data (shell and groups) to GEOM module.
@@ -202,7 +221,8 @@ public:
    * \return true in case of success
    */
   HYDRODATA_EXPORT virtual bool Export( GEOM::GEOM_Gen_var  theGeomEngine,
-                                        SALOMEDS::Study_ptr theStudy ) const;
+                                        SALOMEDS::Study_ptr theStudy,
+                                        QString& theGeomObjEntry ) const;
 
 public:      
   // Public methods to work with Calculation services
@@ -276,18 +296,38 @@ public:
     const gp_XY&                  thePoint,
     const Handle(HYDROData_Zone)& theZone ) const;
 
+  HYDRODATA_EXPORT void SetAssignmentMode( AssignmentMode theMode );
+  HYDRODATA_EXPORT AssignmentMode GetAssignmentMode() const;
+
+  HYDRODATA_EXPORT void ClearRules( const bool theIsSetToUpdate = true );
+  HYDRODATA_EXPORT void AddRule( const Handle(HYDROData_Object)&    theObject1,
+                                 HYDROData_PriorityType             thePriority,
+                                 const Handle(HYDROData_Object)&    theObject2,
+                                 HYDROData_Zone::MergeAltitudesType theMergeType );
+  HYDRODATA_EXPORT bool GetRule( int theIndex, 
+                                 Handle(HYDROData_Object)&           theObject1,
+                                 HYDROData_PriorityType&             thePriority,
+                                 Handle(HYDROData_Object)&           theObject2,
+                                 HYDROData_Zone::MergeAltitudesType& theMergeType ) const;
+
+  HYDRODATA_EXPORT QString DumpRules() const;
+
+  HYDRODATA_EXPORT HYDROData_Warning GetLastWarning() const;
+
 private:
 
   /**
    * Add new one region for calculation case.
    * The new region is added into the list of reference regions.
    */
-  HYDRODATA_EXPORT virtual Handle(HYDROData_Region) addNewRegion();
+  Handle(HYDROData_Region) addNewRegion( const Handle(HYDROData_Document)& theDoc,
+                                         const QString& thePrefixOrName,
+                                         bool isPrefix = true );
 
   /**
    * Add new one splitted edges group for calculation case.
    */
-  HYDRODATA_EXPORT virtual Handle(HYDROData_SplittedShapesGroup) addNewSplittedGroup();
+  Handle(HYDROData_SplittedShapesGroup) addNewSplittedGroup( const QString& theName );
 
   /**
    * Exports the given faces as shell and the given groups to GEOM module.
@@ -297,10 +337,11 @@ private:
    * \param theSplittedGroups the list of groups
    * \return true in case of success
    */
-  HYDRODATA_EXPORT bool Export( GEOM::GEOM_Gen_var                            theGeomEngine,
-                                SALOMEDS::Study_ptr                           theStudy,
-                                const TopTools_ListOfShape&                   theFaces,
-                                const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs ) const;
+  bool Export( GEOM::GEOM_Gen_var                            theGeomEngine,
+               SALOMEDS::Study_ptr                           theStudy,
+               const TopTools_ListOfShape&                   theFaces,
+               const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
+               QString& theGeomObjEntry ) const;
 
   /**
    * Publish the given shape in GEOM as a GEOM object.
@@ -313,10 +354,22 @@ private:
   GEOM::GEOM_Object_ptr publishShapeInGEOM( GEOM::GEOM_Gen_var  theGeomEngine,
                                             SALOMEDS::Study_ptr theStudy,
                                             const TopoDS_Shape& theShape, 
-                                            const QString&      theName ) const;
+                                            const QString&      theName,
+                                            QString& theGeomObjEntry ) const;
 
-protected:
+  void CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
+                         const HYDROData_SplitToZonesTool::SplitDataList& theZones );
+  void CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
+                          const HYDROData_SplitToZonesTool::SplitDataList& theZones );
+
+  void CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
+                            const HYDROData_SplitToZonesTool::SplitDataList& theEdges );
+
+  void DumpRulesToPython( const QString& theCalcCaseName, QStringList& theScript ) const;
 
+  void SetWarning( HYDROData_WarningType theType = WARN_OK, const QString& theData = "" );
+
+protected:
   friend class HYDROData_Iterator;
 
   /**
@@ -329,6 +382,14 @@ protected:
    * Destructs properties of the object and object itself, removes it from the document.
    */
   HYDRODATA_EXPORT ~HYDROData_CalculationCase();
+
+  void DumpSampleMeshing( QStringList& theScript,
+                          const QString& theStudyName,
+                          const QString& theGeomShapeName,
+                          const QString& theMeshName ) const;
+
+private:
+  HYDROData_Warning myLastWarning;
 };
 
 #endif
index 5f95e02b3a6736a697daf18e2dccf05db5bb6426..3568066a333787753c5577adcae0b68ca70ba34c 100644 (file)
@@ -267,6 +267,7 @@ QStringList HYDROData_Document::DumpToPython( MapOfTreatedObjects& theTreatedObj
 
   if ( theIsMultiFile )
   {
+    aResScript << QString( "import salome" );
     aResScript << QString( "" );
     aResScript << QString( "def RebuildData( theStudy ):" );
     aResScript << QString( "  %1 = HYDROData_Document.Document( theStudy._get_StudyId() );" ).arg( aDocName );
index fc5fe6c2d82493c5dc07de427a120fdc2e67090f..ba2cb941f77c21b43c12ba93f98eb9ea7e5c00b9 100644 (file)
@@ -46,7 +46,10 @@ QString HYDROData_Entity::GetName() const
 
 QString HYDROData_Entity::GetObjPyName() const
 {
-  return GetName().replace(" ", "_");
+  QString aName = GetName();
+  aName.replace(QRegExp("[\\W]"), "_");
+
+  return aName;
 }
 
 void HYDROData_Entity::SetName(const QString& theName)
@@ -620,4 +623,14 @@ void HYDROData_Entity::setPythonObjectColor( QStringList&         theScript,
               .arg( theColor.blue() ).arg( theColor.alpha() );
 }
 
-
+void HYDROData_Entity::findPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects,
+                                                  QStringList& theScript ) const
+{
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if ( aDocument.IsNull() )
+    return;
+    
+  theScript << QString( "%1 = %2.FindObjectByName( \"%3\" );" ).arg( GetObjPyName() )
+                                                               .arg( aDocument->GetDocPyName() )
+                                                               .arg( GetName() );
+}
index d639c4a7c976cf18704e605e112e34fb6a4a69b0..dcc6912b96d7717a7f5d05a4feaad9eab5c93c72 100644 (file)
@@ -213,7 +213,14 @@ public:
    */
   HYDRODATA_EXPORT virtual void RemoveZLevel();
 
-
+  /**
+    Find the Python object in the document by the object name.
+    @param theTreatedObjects the map of treated objects
+    @param theScript the script
+  */
+  void findPythonReferenceObject( MapOfTreatedObjects&            theTreatedObjects,
+                                  QStringList&                    theScript ) const;
 protected:
 
   friend class HYDROData_Iterator;
@@ -355,8 +362,7 @@ protected:
    * \param theDefColor default color to return if attribute has not been set before
    */
   QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const;
-
+   
 protected:
 
   /**
index b7c8eb54c8eb67c8bcd3b8e14ce4e3228773e869..7d0469ca666487a7b60f89e18154611947cab1e2 100644 (file)
@@ -41,6 +41,9 @@
 
 #include <HYDROData_Projection.h>
 
+#include <SALOMEDSClient.hxx>
+#include <SALOME_NamingService.hxx>
+
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Obstacle,HYDROData_ArtificialObject)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Obstacle,HYDROData_ArtificialObject)
 
@@ -66,14 +69,19 @@ QStringList HYDROData_Obstacle::DumpToPython( MapOfTreatedObjects& theTreatedObj
   if ( !aGeomObjectEntry.IsEmpty() )
   {
     QString aSalomeObjName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "obstacle_sobj" );
-    aResList << QString( "%1 = theStudy.FindObjectID( \"%2\" );" )
-                .arg( aSalomeObjName ).arg( aGeomObjectEntry.ToCString() );
-
-    aResList << QString( "%1.ImportFromGeomIOR( %2.GetIOR() );" )
-                .arg( anObstacleName ).arg( aSalomeObjName );
-
-    aResList << QString( "%1.SetGeomObjectEntry( \"%2\" );" )
-                .arg( anObstacleName ).arg( aGeomObjectEntry.ToCString() );
+    // aResList << QString( "%1 = theStudy.FindObjectID( \"%2\" );" )
+    //            .arg( aSalomeObjName ).arg( aGeomObjectEntry.ToCString() );
+    QString aGeomObjectName( GetGeomObjectName().ToCString() );
+    if ( !aGeomObjectName.isEmpty() ) {
+      aResList << QString( "%1 = theStudy.FindObjectByName( \"%2\", \"GEOM\" )[0];" )
+                  .arg( aSalomeObjName ).arg( aGeomObjectName );
+
+      aResList << QString( "%1.ImportFromGeomIOR( %2.GetIOR() );" )
+                  .arg( anObstacleName ).arg( aSalomeObjName );
+
+      aResList << QString( "%1.SetGeomObjectEntry( %2.GetID() );" )
+                  .arg( anObstacleName ).arg( aSalomeObjName );
+    }
     aResList << QString( "" );
   }
   else if ( !aFilePath.isEmpty() )
@@ -227,6 +235,33 @@ TCollection_AsciiString HYDROData_Obstacle::GetGeomObjectEntry() const
   return aRes;
 }
 
+TCollection_AsciiString HYDROData_Obstacle::GetGeomObjectName() const
+{
+  TCollection_AsciiString aRes;
+
+  int aDocId = -1;
+  if ( !HYDROData_Document::DocumentId( HYDROData_Document::Document( myLab ), aDocId ) || aDocId < 0 ) {
+    return aRes;
+  }
+
+  int argc = 0;
+  char** argv = 0;
+  CORBA::ORB_var anORB = CORBA::ORB_init( argc, argv, "omniORB4"/*CORBA::ORB_ID*/ );
+  SALOME_NamingService aNameService( anORB );
+  
+  CORBA::Object_var aSMObject = aNameService.Resolve("/myStudyManager");
+  SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
+  SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID( aDocId );
+
+  TCollection_AsciiString anEntry = GetGeomObjectEntry();
+  SALOMEDS::SObject_var aSObject = aDSStudy->FindObjectID( anEntry.ToCString() );
+  if ( !aSObject->_is_nil() ) {
+    aRes = TCollection_AsciiString( aSObject->GetName() );
+  }
+
+  return aRes;
+}
+
 void HYDROData_Obstacle::Translate( const double theDx,
                                     const double theDy,
                                     const double theDz )
index 3641ba9d592f978e8f87c5243df000762f2eeb74..85373efd445e591ed92df6a8e18ab5893a9e81aa 100644 (file)
@@ -121,6 +121,10 @@ public:
    */
   HYDRODATA_EXPORT TCollection_AsciiString GetGeomObjectEntry() const;
 
+  /**
+   * Returns the imported GEOM object name.
+   */
+  HYDRODATA_EXPORT TCollection_AsciiString GetGeomObjectName() const;
 
   /**
    * Translate the obstacle to the given distance.
diff --git a/src/HYDROData/HYDROData_PriorityQueue.cxx b/src/HYDROData/HYDROData_PriorityQueue.cxx
new file mode 100644 (file)
index 0000000..075f70a
--- /dev/null
@@ -0,0 +1,275 @@
+
+#include <HYDROData_PriorityQueue.h>
+#include <HYDROData_CalculationCase.h>
+#include <HYDROData_Iterator.h>
+#include <TDataStd_ReferenceList.hxx>
+#include <TDataStd_Integer.hxx>
+#include <TDF_ChildIterator.hxx>
+
+HYDROData_PriorityQueue::HYDROData_PriorityQueue( HYDROData_CalculationCase* theCalcCase )
+{
+  myGeomObjects = theCalcCase->GetGeometryObjects();
+  for( int i=myGeomObjects.Lower(), n=myGeomObjects.Upper(); i<=n; i++ )
+  {
+    Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( myGeomObjects.Value( i ) );
+    if( !anObj.IsNull() )
+    {
+      QString anObjName = anObj->GetName();
+      myNames[anObjName] = anObj;
+    }
+  }
+
+  myRules = GetRules( theCalcCase->Label().FindChild( HYDROData_CalculationCase::DataTag_CustomRules ) );
+}
+
+HYDROData_PriorityQueue::~HYDROData_PriorityQueue()
+{
+}
+
+Handle(HYDROData_Object) HYDROData_PriorityQueue::GetMostPriorityObject( const QStringList& theZoneObjects,
+                                                                         HYDROData_Zone::MergeAltitudesType& theMergeType ) const
+{
+  QStringList aSortedZoneObjects;
+  for( int i=myGeomObjects.Lower(), n=myGeomObjects.Upper(); i<=n; i++ )
+  {
+    QString aName = myGeomObjects.Value( i )->GetName();
+    if( theZoneObjects.contains( aName ) )
+      aSortedZoneObjects.append( aName );
+  }
+
+  Handle(HYDROData_Object) aMostPriorityObj;
+  theMergeType = HYDROData_Zone::Merge_UNKNOWN;
+  QStringList::const_iterator anIt = aSortedZoneObjects.begin(), aLast = aSortedZoneObjects.end();
+  for( ; anIt!=aLast; anIt++ )
+  {
+    HYDROData_Zone::MergeAltitudesType aLocalMerge = HYDROData_Zone::Merge_UNKNOWN;
+    Handle(HYDROData_Object) anObj = myNames[*anIt];
+    if( !anObj.IsNull() )
+    {
+      if( aMostPriorityObj.IsNull() )
+      {
+        aMostPriorityObj = anObj;
+        continue;
+      }
+
+      bool isMorePriority = IsMorePriority( anObj, aMostPriorityObj, aLocalMerge );
+
+      if( isMorePriority )
+        aMostPriorityObj = anObj;
+
+      if( aLocalMerge != HYDROData_Zone::Merge_UNKNOWN && 
+          ( theMergeType==HYDROData_Zone::Merge_UNKNOWN || isMorePriority ) )
+        theMergeType = aLocalMerge;
+    }
+  }
+  return aMostPriorityObj;
+}
+
+bool HYDROData_PriorityQueue::IsMorePriority( const Handle(HYDROData_Object)& theObj1,
+                                              const Handle(HYDROData_Object)& theObj2,
+                                              HYDROData_Zone::MergeAltitudesType& theMergeType ) const
+{
+  // 1. First we check custom rules
+  HYDROData_ListOfRules::const_iterator anIt = myRules.begin(), aLast = myRules.end();
+  for( ; anIt!=aLast; anIt++ )
+  {
+    if( anIt->Object1->Label()==theObj1->Label() && anIt->Object2->Label()==theObj2->Label() )
+    {
+      theMergeType = anIt->MergeType;
+      return anIt->Priority==GREATER;
+    }
+    if( anIt->Object1->Label()==theObj2->Label() && anIt->Object2->Label()==theObj1->Label() )
+    {
+      theMergeType = anIt->MergeType;
+      return anIt->Priority==LESS;
+    }
+  }
+
+  // 2. If no custom rule found, the standard ordering list is applied
+  for( int i=myGeomObjects.Lower(), n=myGeomObjects.Upper(); i<=n; i++ )
+  {
+    if( myGeomObjects.Value( i )->Label() == theObj1->Label() )
+    {
+      theMergeType = HYDROData_Zone::Merge_Object;
+      return true;
+    }
+    if( myGeomObjects.Value( i )->Label() == theObj2->Label() )
+    {
+      theMergeType = HYDROData_Zone::Merge_Object;
+      return false;
+    }
+  }
+  return false;
+}
+
+void HYDROData_PriorityQueue::ClearRules( TDF_Label& theRulesLabel )
+{
+  theRulesLabel.ForgetAllAttributes( true );
+}
+
+enum HYDROData_PriorityQueueTag
+{
+  Object1_Tag,
+  Priority_Tag,
+  Object2_Tag,
+  Merge_Tag,
+};
+
+void HYDROData_PriorityQueue::AddRule( TDF_Label&                         theRulesLabel,
+                                       const Handle(HYDROData_Object)&    theObject1,
+                                       HYDROData_PriorityType             thePriority,
+                                       const Handle(HYDROData_Object)&    theObject2,
+                                       HYDROData_Zone::MergeAltitudesType theMergeType )
+{
+  // Get the last rule index
+  Standard_Integer aRuleIndex = 0;
+  Handle(TDataStd_Integer) anIntVal;
+  if ( theRulesLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) ) {
+    aRuleIndex = anIntVal->Get();
+  }
+
+  TDF_Label aNewRuleLab = theRulesLabel.FindChild( aRuleIndex );
+
+  TDF_Label anObj1Lab = aNewRuleLab.FindChild( Object1_Tag );
+  Handle(TDataStd_ReferenceList) aRefs = TDataStd_ReferenceList::Set( anObj1Lab );
+  aRefs->Append( theObject1->Label() );
+  
+  TDF_Label aPriorityLab = aNewRuleLab.FindChild( Priority_Tag );
+  TDataStd_Integer::Set( aPriorityLab, thePriority );
+
+  TDF_Label anObj2Lab = aNewRuleLab.FindChild( Object2_Tag );
+  aRefs = TDataStd_ReferenceList::Set( anObj2Lab );
+  aRefs->Append( theObject2->Label() );
+
+  TDF_Label aMergeLab = aNewRuleLab.FindChild( Merge_Tag );
+  TDataStd_Integer::Set( aMergeLab, theMergeType );
+
+  // Increment the last rule index
+  TDataStd_Integer::Set( theRulesLabel, aRuleIndex + 1 );
+}
+
+HYDROData_ListOfRules HYDROData_PriorityQueue::GetRules( const TDF_Label& theRulesLabel )
+{
+  HYDROData_ListOfRules aRules;
+
+  Handle(TDataStd_ReferenceList) aRefs1, aRefs2;
+  Handle(TDataStd_Integer) aPriorityAttr, aMergeAttr;
+
+  TDF_ChildIterator anIt( theRulesLabel );
+  for( ; anIt.More(); anIt.Next() )
+  {
+    TDF_Label aRuleLabel = anIt.Value();
+
+    bool isObj1OK = aRuleLabel.FindChild    ( Object1_Tag ). FindAttribute( TDataStd_ReferenceList::GetID(), aRefs1 );
+    bool isPriorityOK = aRuleLabel.FindChild( Priority_Tag ).FindAttribute( TDataStd_Integer::GetID(),       aPriorityAttr );
+    bool isObj2OK = aRuleLabel.FindChild    ( Object2_Tag ). FindAttribute( TDataStd_ReferenceList::GetID(), aRefs2 );
+    bool isMergeOK = aRuleLabel.FindChild   ( Merge_Tag ).   FindAttribute( TDataStd_Integer::GetID(),       aMergeAttr );
+
+    if( isObj1OK && isPriorityOK && isObj2OK && isMergeOK )
+    {
+      HYDROData_CustomRule aRule;
+      aRule.Object1 = Handle_HYDROData_Object::DownCast( HYDROData_Iterator::Object( aRefs1->First() ) );
+      aRule.Priority = ( HYDROData_PriorityType ) aPriorityAttr->Get();
+      aRule.Object2 = Handle_HYDROData_Object::DownCast( HYDROData_Iterator::Object( aRefs2->First() ) );
+      aRule.MergeType = ( HYDROData_Zone::MergeAltitudesType ) aMergeAttr->Get();
+      aRules.append( aRule );
+    }
+  }
+
+  return aRules;
+}
+
+QString HYDROData_PriorityQueue::DumpRules( const TDF_Label& theRulesLab )
+{
+  QString aDump = "Rules:\n";
+  HYDROData_ListOfRules aRules = GetRules( theRulesLab );
+  HYDROData_ListOfRules::const_iterator anIt = aRules.begin(), aLast = aRules.end();
+  for( ; anIt!=aLast; anIt++ )
+  {
+    QString aRule = anIt->Object1->GetName() + " ";
+    aRule += ( anIt->Priority == LESS ? "<" : ">" ) + QString( " " );
+    aRule += anIt->Object2->GetName() + " ";
+
+    switch( anIt->MergeType )
+    {
+    case HYDROData_Zone::Merge_UNKNOWN:
+      aRule += "unknown";
+      break;
+    case HYDROData_Zone::Merge_ZMIN:
+      aRule += "zmin";
+      break;
+    case HYDROData_Zone::Merge_ZMAX:
+      aRule += "zmax";
+      break;
+    case HYDROData_Zone::Merge_Object:
+      aRule += "object";
+      break;
+    }
+    aDump += aRule + "\n";
+  }
+  return aDump;
+}
+
+void HYDROData_PriorityQueue::DumpRulesToPython( const TDF_Label& theRulesLab,
+                                                 const QString& theCalcCaseName,
+                                                 QStringList& theScript )
+{
+  HYDROData_ListOfRules aRules = GetRules( theRulesLab );
+  HYDROData_ListOfRules::const_iterator anIt = aRules.begin(), aLast = aRules.end();
+  for( ; anIt!=aLast; anIt++ )
+  {
+    QString anObj1 = anIt->Object1->GetObjPyName();
+    QString anObj2 = anIt->Object2->GetObjPyName();
+    QString aPriority = anIt->Priority == LESS ? "LESS" : "GREATER";
+    QString aMergeType;
+
+    switch( anIt->MergeType )
+    {
+    case HYDROData_Zone::Merge_UNKNOWN:
+      aMergeType = "HYDROData_Zone.Merge_UNKNOWN";
+      break;
+    case HYDROData_Zone::Merge_ZMIN:
+      aMergeType = "HYDROData_Zone.Merge_ZMIN";
+      break;
+    case HYDROData_Zone::Merge_ZMAX:
+      aMergeType = "HYDROData_Zone.Merge_ZMAX";
+      break;
+    case HYDROData_Zone::Merge_Object:
+      aMergeType = "HYDROData_Zone.Merge_Object";
+      break;
+    }
+
+    QString aRule = QString( "%0.AddRule( %1, %2, %3, %4 )" ).
+      arg( theCalcCaseName ).arg( anObj1 ).arg( aPriority ).arg( anObj2 ).arg( aMergeType );
+
+    theScript << aRule;
+  }
+}
+
+bool HYDROData_PriorityQueue::GetRule( const TDF_Label& theRulesLab,
+                                       int theIndex, 
+                                       Handle(HYDROData_Object)&           theObject1,
+                                       HYDROData_PriorityType&             thePriority,
+                                       Handle(HYDROData_Object)&           theObject2,
+                                       HYDROData_Zone::MergeAltitudesType& theMergeType )
+{
+  TDF_Label aRuleLabel = theRulesLab.FindChild( theIndex );
+
+  Handle(TDataStd_ReferenceList) aRefs1, aRefs2;
+  Handle(TDataStd_Integer) aPriorityAttr, aMergeAttr;
+
+  bool isObj1OK = aRuleLabel.FindChild    ( Object1_Tag ). FindAttribute( TDataStd_ReferenceList::GetID(), aRefs1 );
+  bool isPriorityOK = aRuleLabel.FindChild( Priority_Tag ).FindAttribute( TDataStd_Integer::GetID(),       aPriorityAttr );
+  bool isObj2OK = aRuleLabel.FindChild    ( Object2_Tag ). FindAttribute( TDataStd_ReferenceList::GetID(), aRefs2 );
+  bool isMergeOK = aRuleLabel.FindChild   ( Merge_Tag ).   FindAttribute( TDataStd_Integer::GetID(),       aMergeAttr );
+
+  bool isOK = isObj1OK && isPriorityOK && isObj2OK && isMergeOK;
+  if( isOK )
+  {
+    theObject1   = Handle_HYDROData_Object::DownCast( HYDROData_Iterator::Object( aRefs1->First() ) );
+    thePriority  = ( HYDROData_PriorityType ) aPriorityAttr->Get();
+    theObject2   = Handle_HYDROData_Object::DownCast( HYDROData_Iterator::Object( aRefs2->First() ) );
+    theMergeType = ( HYDROData_Zone::MergeAltitudesType ) aMergeAttr->Get();
+  }
+  return isOK;
+}
diff --git a/src/HYDROData/HYDROData_PriorityQueue.h b/src/HYDROData/HYDROData_PriorityQueue.h
new file mode 100644 (file)
index 0000000..62c8708
--- /dev/null
@@ -0,0 +1,66 @@
+
+#ifndef HYDROData_PriorityQueue_HeaderFile
+#define HYDROData_PriorityQueue_HeaderFile
+
+#include <QMap>
+#include <HYDROData_Object.h>
+#include <HYDROData_Zone.h>
+
+class HYDROData_CalculationCase;
+
+enum HYDROData_PriorityType
+{
+  LESS,
+  GREATER,
+};
+
+struct HYDROData_CustomRule
+{
+  Handle(HYDROData_Object)           Object1;
+  HYDROData_PriorityType             Priority;
+  Handle(HYDROData_Object)           Object2;
+  HYDROData_Zone::MergeAltitudesType MergeType;
+};
+
+typedef QList<HYDROData_CustomRule> HYDROData_ListOfRules;
+
+class HYDROData_PriorityQueue
+{
+public:
+  HYDROData_PriorityQueue( HYDROData_CalculationCase* );
+  ~HYDROData_PriorityQueue();
+
+  Handle_HYDROData_Object GetMostPriorityObject( const QStringList& theZoneObjects,
+                                                 HYDROData_Zone::MergeAltitudesType& theMergeType ) const;
+
+  bool IsMorePriority( const Handle(HYDROData_Object)& theObj1,
+                       const Handle(HYDROData_Object)& theObj2,
+                       HYDROData_Zone::MergeAltitudesType& theMergeType ) const;
+
+  static void ClearRules( TDF_Label& theRulesLabel );
+  static void AddRule( TDF_Label& theRulesLabel,
+                       const Handle(HYDROData_Object)&    theObject1,
+                       HYDROData_PriorityType             thePriority,
+                       const Handle(HYDROData_Object)&    theObject2,
+                       HYDROData_Zone::MergeAltitudesType theMergeType );
+  static HYDROData_ListOfRules GetRules( const TDF_Label& theRulesLabel );
+  static QString DumpRules( const TDF_Label& theRulesLab );
+  static void DumpRulesToPython( const TDF_Label& theRulesLab,
+                                 const QString& theCalcCaseName,
+                                 QStringList& theScript );
+  static bool GetRule( const TDF_Label& theRulesLab,
+                       int theIndex, 
+                       Handle(HYDROData_Object)&           theObject1,
+                       HYDROData_PriorityType&             thePriority,
+                       Handle(HYDROData_Object)&           theObject2,
+                       HYDROData_Zone::MergeAltitudesType& theMergeType );
+private:
+  typedef QMap<QString, Handle(HYDROData_Object)> MapNameToObject;
+
+  HYDROData_SequenceOfObjects myGeomObjects;  ///< the ordered list of objects (default priority)
+  MapNameToObject             myNames;        ///< the map of name to object
+  HYDROData_ListOfRules       myRules;        ///< the list of rules
+};
+
+#endif
+
index ac6a4f757ca6b2ed550d0f98e7b3085005363f74..45d7b9e7149cb7a66bf811c12685be9e897815c1 100644 (file)
@@ -4,8 +4,10 @@
 #include "HYDROData_CalculationCase.h"
 #include "HYDROData_Document.h"
 #include "HYDROData_Iterator.h"
+#include "HYDROData_Object.h"
 #include "HYDROData_ShapesTool.h"
 #include "HYDROData_Zone.h"
+#include "HYDROData_Tool.h"
 
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
@@ -74,6 +76,8 @@ HYDROData_SequenceOfObjects HYDROData_Region::GetAllReferenceObjects() const
 
 bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone )
 {
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+
   if ( theZone.IsNull() )
     return false;
   
@@ -85,7 +89,7 @@ bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone )
     Handle(HYDROData_Region)::DownCast( theZone->GetFatherObject() );
   if ( !aFatherRegion.IsNull() && aFatherRegion->Label() != myLab )
   {
-    Handle(HYDROData_Zone) aNewZone = addNewZone();
+    Handle(HYDROData_Zone) aNewZone = addNewZone( aDocument, "", TopoDS_Face(), QStringList() );
     theZone->CopyTo( aNewZone );
 
     // To prevent changing of stored shape
@@ -133,7 +137,10 @@ void HYDROData_Region::RemoveZones()
   myLab.FindChild( DataTag_ChildZone ).ForgetAllAttributes( true );
 }
 
-Handle(HYDROData_Zone) HYDROData_Region::addNewZone()
+Handle(HYDROData_Zone) HYDROData_Region::addNewZone( const Handle(HYDROData_Document)& theDoc,
+                                                     const QString& thePrefix,
+                                                     const TopoDS_Face& theFace,
+                                                     const QStringList& theRefObjects )
 {
   TDF_Label aNewLab = myLab.FindChild( DataTag_ChildZone ).NewChild();
 
@@ -141,6 +148,23 @@ Handle(HYDROData_Zone) HYDROData_Region::addNewZone()
     Handle(HYDROData_Zone)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_ZONE ) );
   AddZone( aNewZone );
 
+  QString aZoneName = HYDROData_Tool::GenerateObjectName( theDoc, thePrefix );
+  aNewZone->SetName( aZoneName );
+
+  aNewZone->SetShape( theFace );
+
+  // Add the reference object for zone
+  for ( int i = 0, n = theRefObjects.length(); i < n; ++i )
+  {
+    const QString& anObjName = theRefObjects.at( i );
+    Handle(HYDROData_Object) aRefObject = 
+      Handle(HYDROData_Object)::DownCast( theDoc->FindObjectByName( anObjName ) );
+    if ( aRefObject.IsNull() )
+      continue;
+
+    aNewZone->AddGeometryObject( aRefObject );
+  }
+
   return aNewZone;
 }
 
@@ -347,3 +371,54 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs*
   
   return aResShape;
 }
+
+QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
+{
+  QStringList aResList;
+
+  // Find region
+  findPythonReferenceObject( theTreatedObjects, aResList );
+
+  // Add zones
+  HYDROData_SequenceOfObjects aZones = GetZones();
+  HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
+  for ( ; aZonesIter.More(); aZonesIter.Next() ) {
+    Handle(HYDROData_Zone) aZone =
+      Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
+    if ( aZone.IsNull() ) {
+      continue;
+    }
+    
+    // find zone
+    aZone->findPythonReferenceObject( theTreatedObjects, aResList );
+    theTreatedObjects.insert( aZone->GetName(), aZone );
+    
+    // set zone merge type
+    QString aMergeTypeStr;
+    HYDROData_Zone::MergeAltitudesType aMergeType = aZone->GetMergeType();
+    if ( aMergeType == HYDROData_Zone::Merge_ZMIN ) {
+      aMergeTypeStr = "HYDROData_Zone.Merge_ZMIN";
+    } else if ( aMergeType == HYDROData_Zone::Merge_ZMAX ) {
+      aMergeTypeStr = "HYDROData_Zone.Merge_ZMAX";
+    } else if ( aMergeType == HYDROData_Zone::Merge_Object ) {
+      aMergeTypeStr = "HYDROData_Zone.Merge_Object";
+    }
+
+    if ( !aMergeTypeStr.isEmpty() ) {
+      aResList << QString( "%1.SetMergeType( %2 )" ).arg( aZone->GetObjPyName() ).arg( aMergeTypeStr );
+    }
+    if ( aMergeType == HYDROData_Zone::Merge_Object ) {
+      Handle(HYDROData_IAltitudeObject) aMergeAltitude = aZone->GetMergeAltitude();
+      if ( !aMergeAltitude.IsNull() ) {
+        aMergeAltitude->findPythonReferenceObject( theTreatedObjects, aResList );
+        aResList << QString( "%1.SetMergeAltitude( %2 )" ).arg( aZone->GetObjPyName() )
+                                                          .arg( aMergeAltitude->GetObjPyName() );
+      }
+    }
+
+    // add zone
+    setPythonReferenceObject( theTreatedObjects, aResList, aZone, "AddZone" );
+  }
+
+  return aResList;
+}
\ No newline at end of file
index 3307b324377ebc93527832bd8765e24bb01f322c..45fd385c0847f5e58108c2c7b30f49a1f968e4eb 100644 (file)
@@ -8,8 +8,10 @@
 DEFINE_STANDARD_HANDLE(HYDROData_Region, HYDROData_Entity)
 
 class Handle(HYDROData_Zone);
-
+class Handle(HYDROData_Document);
 class TopoDS_Shape;
+class TopoDS_Face;
+class QStringList;
 
 /**\class HYDROData_Region
  * \brief Regions are groups (lists) of zones, they can include one or several zones.
@@ -37,6 +39,10 @@ public:
    */
   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_REGION; }
 
+  /**
+   * Dump object to Python script representation.
+   */
+  HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
 
   /**
    * Returns flag indicating that object is updateble or not.
@@ -97,7 +103,10 @@ protected:
    * Create new one reference zone for region on child label.
    * The new zone is added into the list of reference zones.
    */
-  HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) addNewZone();
+  HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) addNewZone( const Handle(HYDROData_Document)& theDoc,
+                                                              const QString& thePrefix,
+                                                              const TopoDS_Face& theFace,
+                                                              const QStringList& theRefObjects );
 
 protected:
 
index fabf15d9340c3b2e68d4ba38a4dda6aebf26cd1e..3df841ed040d9a09a29f351170c004f87d8f46ea 100644 (file)
@@ -201,7 +201,7 @@ HYDROData_SplitToZonesTool::SplitDataList
     QStringList aListOfNames;
     for (int i=0;i < anInputGroupList.size() ;i++) {
       const TopoDS_Shape& aSh = anInputGroupList.at(i).Shape;
-      aDM3.Bind(aSh, anInputGroupList.at(i).ObjectNames);
+      aDM3.Add(aSh, anInputGroupList.at(i).ObjectNames);
     }
   }
 
@@ -214,7 +214,7 @@ HYDROData_SplitToZonesTool::SplitDataList
   aBB.MakeCompound(aCmp);
   for (int i=0;i < anInputSplitDataList.size() ;i++) {
     const TopoDS_Shape& aSh = anInputSplitDataList.at(i).Shape;
-    aDM3.Bind(aSh, anInputSplitDataList.at(i).ObjectNames);
+    aDM3.Add(aSh, anInputSplitDataList.at(i).ObjectNames);
     aLS.Append(aSh);
     aBB.Add(aCmp,aSh);
 #ifdef DEB_SPLIT_TO_ZONES
@@ -277,7 +277,7 @@ HYDROData_SplitToZonesTool::SplitDataList
           ********************************************************************* */
       if(!foundF) // face is not modified
         aList.Append (anIt.Value());
-      aDM1.Bind(anIt.Value(), aList);
+      aDM1.Add(anIt.Value(), aList);
   #ifdef DEB_SPLIT_TO_ZONES
       TCollection_AsciiString aName;
   #endif
@@ -313,7 +313,7 @@ HYDROData_SplitToZonesTool::SplitDataList
             cout << aName.ToCString()<< " = " << exp.Current().TShape() <<endl;
   #endif
           }
-          aDM1.Bind(exp.Current(), aList);
+          aDM1.Add(exp.Current(), aList);
         }
       }
     }
@@ -352,10 +352,10 @@ HYDROData_SplitToZonesTool::SplitDataList
               aBndView.Add(anEdge);
               QStringList aListOfNames;
               aListOfNames.append(aBndName);
-              aDM3.Bind(anEdge, aListOfNames);
+              aDM3.Add(anEdge, aListOfNames);
               TopTools_ListOfShape aList;
               aList.Append(anEdge);
-              aDM1.Bind(anEdge,aList);
+              aDM1.Add(anEdge,aList);
             }
             HYDROData_MapOfShape aView;
             exp.Init (aResult, TopAbs_FACE);
@@ -365,7 +365,7 @@ HYDROData_SplitToZonesTool::SplitDataList
                 const TopTools_ListOfShape& aListOfNew = mkCom.Modified(aFace);
                 //cout << "Modified: " << aListOfNew.Extent() <<endl;                                    
                 if(!aListOfNew.IsEmpty()) {
-                  aDM4.Bind(aFace, aListOfNew);
+                  aDM4.Add(aFace, aListOfNew);
 #ifdef DEB_SPLIT_TO_ZONES
                   //TCollection_AsciiString aName = aNam + i + ".brep";
                   //BRepTools::Write(aListOfNew.Last(), aName.ToCString());                
@@ -384,7 +384,7 @@ HYDROData_SplitToZonesTool::SplitDataList
                        else {
                         TopTools_ListOfShape aList; 
                         aList.Append(aFace);
-                        aDM4.Bind(aFace, aList); //the same face - not modified
+                        aDM4.Add(aFace, aList); //the same face - not modified
                        }
                     }
              }
@@ -396,7 +396,7 @@ HYDROData_SplitToZonesTool::SplitDataList
                  aView.Add(anEdge);
                  const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);                 
                  if(!aListOfNewEd.IsEmpty())
-                   aDM4.Bind(anEdge, aListOfNewEd);
+                   aDM4.Add(anEdge, aListOfNewEd);
                  else {
                    if(!mkCom.IsDeleted(anEdge)) {
                      const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
@@ -405,7 +405,7 @@ HYDROData_SplitToZonesTool::SplitDataList
                      } else {
                        TopTools_ListOfShape aList; 
                        aList.Append(anEdge);
-                       aDM4.Bind(anEdge, aList);//the same edge - not modified
+                       aDM4.Add(anEdge, aList);//the same edge - not modified
                      }
                    }
                  }
@@ -432,7 +432,7 @@ HYDROData_SplitToZonesTool::SplitDataList
              }
 #endif
              if(!aListOfNewEd.IsEmpty())
-               aDM4.Bind(anEdge, aListOfNewEd);
+               aDM4.Add(anEdge, aListOfNewEd);
              else {
                if(!mkCom.IsDeleted(anEdge)) {
                  const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
@@ -441,7 +441,7 @@ HYDROData_SplitToZonesTool::SplitDataList
                  } else {
                    TopTools_ListOfShape aList; 
                    aList.Append(anEdge);
-                   aDM4.Bind(anEdge, aList);//the same edge - not modified
+                   aDM4.Add(anEdge, aList);//the same edge - not modified
                  }
                }
              }
@@ -456,13 +456,13 @@ HYDROData_SplitToZonesTool::SplitDataList
              TopTools_ListOfShape aList;
              aList.Append(aKey);
              const TopTools_ListOfShape& aListOfNew = mIt.Value();
-             aDM1.Bind(aKey, aListOfNew);
+             aDM1.Add(aKey, aListOfNew);
              TopTools_ListIteratorOfListOfShape it(aListOfNew);
              for(;it.More();it.Next()) {
-               if(!aDM2.IsBound(it.Value()))
-                 aDM2.Bind(it.Value(), aList);
+               if(!aDM2.Contains(it.Value()))
+                 aDM2.Add(it.Value(), aList);
                else {
-                 TopTools_ListOfShape& aList = aDM2.ChangeFind(it.Value());
+                 TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it.Value());
                  aList.Prepend(aKey);
                }
              }
@@ -477,16 +477,16 @@ HYDROData_SplitToZonesTool::SplitDataList
              const TopTools_ListOfShape& aListOfNew = aMIt.Value();
              TopTools_ListIteratorOfListOfShape it(aListOfNew);
              for(;it.More();it.Next()) {// iterate new: b1, b2, b3...
-               if(!aDM4.IsBound(it.Value())) // bi - is deleted
+               if(!aDM4.Contains(it.Value())) // bi - is deleted
                  continue; // go to the next bi
                else {
-                  const TopTools_ListOfShape& aListOfNew4 = aDM4.Find(it.Value());
+                 const TopTools_ListOfShape& aListOfNew4 = aDM4.FindFromKey(it.Value());
                   TopTools_ListIteratorOfListOfShape it4(aListOfNew4); // {c1, c2, c3,...}
                   for(;it4.More();it4.Next()) {
-                    if(!aDM2.IsBound(it4.Value()))
-                      aDM2.Bind(it4.Value(), aList);
+                    if(!aDM2.Contains(it4.Value()))
+                      aDM2.Add(it4.Value(), aList);
                     else {
-                      TopTools_ListOfShape& aList = aDM2.ChangeFind(it4.Value());
+                      TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it4.Value());
                       aList.Prepend(aKey);
                     }
                   }
@@ -513,10 +513,10 @@ HYDROData_SplitToZonesTool::SplitDataList
       const TopTools_ListOfShape& aListOfNew = aMIt.Value();
       TopTools_ListIteratorOfListOfShape it(aListOfNew);
       for(;it.More();it.Next()) {
-        if(!aDM2.IsBound(it.Value()))
-          aDM2.Bind(it.Value(), aList);
+        if(!aDM2.Contains(it.Value()))
+          aDM2.Add(it.Value(), aList);
         else {
-          TopTools_ListOfShape& aList = aDM2.ChangeFind(it.Value());
+          TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it.Value());
           aList.Prepend(aKey);
         }
       }
@@ -546,8 +546,8 @@ HYDROData_SplitToZonesTool::SplitDataList
     TopTools_ListIteratorOfListOfShape it(aListOfOld);
     for(int j =1;it.More();it.Next(),j++) {    
       const TopoDS_Shape& aSh = it.Value(); //old
-      if(aDM3.IsBound(aSh)) {
-        const QStringList& ObjectNames = aDM3.Find(aSh);    
+      if(aDM3.Contains(aSh)) {
+        const QStringList& ObjectNames = aDM3.FindFromKey(aSh);    
         aListOfNames.append(ObjectNames);
 #ifdef DEB_SPLIT_TO_ZONES
         TCollection_AsciiString aName = aNam4 + i +"_" + j + ".brep";
index c80f66fe3ef6480c26c13c089214d6305d35d70d..67b6bdc046c4276066f7afde90c4218172b38928 100644 (file)
@@ -8,8 +8,8 @@
 #include <TopoDS_Compound.hxx>
 #include <TopoDS_Face.hxx>
 #include <TopTools_ShapeMapHasher.hxx>
-#include <NCollection_Map.hxx>
-#include <NCollection_DataMap.hxx>
+#include <NCollection_IndexedMap.hxx>
+#include <NCollection_IndexedDataMap.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <QStringList>
 
@@ -54,11 +54,11 @@ public:
 
   typedef QList        <SplitData> SplitDataList;
   typedef QListIterator<SplitData> SplitDataListIterator;  
-  typedef NCollection_Map<TopoDS_Shape, TopTools_ShapeMapHasher> HYDROData_MapOfShape;
+  typedef NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> HYDROData_MapOfShape;
   typedef HYDROData_MapOfShape::Iterator HYDROData_MapIteratorOfMapOfShape;
-  typedef NCollection_DataMap<TopoDS_Shape, TopTools_ListOfShape, TopTools_ShapeMapHasher> HYDROData_DataMapOfShapeListOfShape;
+  typedef NCollection_IndexedDataMap<TopoDS_Shape, TopTools_ListOfShape, TopTools_ShapeMapHasher> HYDROData_DataMapOfShapeListOfShape;
   typedef HYDROData_DataMapOfShapeListOfShape::Iterator HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape;
-  typedef NCollection_DataMap<TopoDS_Shape,  QStringList, TopTools_ShapeMapHasher> HYDROData_DataMapOfShapeListOfString;
+  typedef NCollection_IndexedDataMap<TopoDS_Shape,  QStringList, TopTools_ShapeMapHasher> HYDROData_DataMapOfShapeListOfString;
   typedef HYDROData_DataMapOfShapeListOfString::Iterator HYDROData_DataMapIteratorOfDataMapOfShapeListOfString;
   #undef _NCollection_MapHasher
 
diff --git a/src/HYDROData/HYDROData_Warning.h b/src/HYDROData/HYDROData_Warning.h
new file mode 100644 (file)
index 0000000..b8ba7ae
--- /dev/null
@@ -0,0 +1,18 @@
+
+#ifndef HYDROData_Warnings_HeaderFile
+#define HYDROData_Warnings_HeaderFile
+
+enum HYDROData_WarningType
+{
+  WARN_OK = 0,
+  WARN_EMPTY_REGIONS = 1,
+};
+
+struct HYDROData_Warning
+{
+  HYDROData_WarningType Type;
+  QString               Data;
+};
+
+
+#endif
index a3acda812aaf8aa4843d2ff118f025639d4f8942..a1928801f766be934ac573bb4731f2f49e492fb5 100644 (file)
@@ -99,6 +99,8 @@ set(PROJECT_HEADERS
     HYDROGUI_OrderedListWidget.h
     HYDROGUI_ListSelector.h
     HYDROGUI_ZLayers.h
+    HYDROGUI_PriorityWidget.h
+       HYDROGUI_PriorityTableModel.h
 )
 
 QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS})
@@ -200,6 +202,8 @@ set(PROJECT_SOURCES
     HYDROGUI_ListSelector.cxx
     HYDROGUI_ZLayers.cxx
     HYDROGUI_ZLayers2.cxx
+    HYDROGUI_PriorityWidget.cxx
+       HYDROGUI_PriorityTableModel.cxx
 )
 
 add_definitions(
index ba31ad82e4c0b010e89da283171866f569a8ca70..9b2bfda7ae5aeae83e36fd5b4e90721592e8997d 100644 (file)
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_DataBrowser.h"
 #include "HYDROGUI_DataModel.h"
+#include "HYDROGUI_ListSelector.h"
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_DataObject.h"
 #include "HYDROGUI_NameValidator.h"
 #include "HYDROGUI_Region.h"
 #include "HYDROGUI_Zone.h"
+#include "HYDROGUI_OrderedListWidget.h"
+#include "HYDROGUI_PriorityWidget.h"
 
 #include <HYDROData_Document.h>
 #include <HYDROData_Entity.h>
 #include <SUIT_Study.h>
 
 #include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
 #include <SUIT_Desktop.h>
 #include <SUIT_MessageBox.h>
 
+#include <QButtonGroup>
+#include <QComboBox>
 #include <QGroupBox>
 #include <QLabel>
 #include <QLayout>
 #include <QListWidget>
 #include <QPicture>
 #include <QPushButton>
+#include <QRadioButton>
+#include <QSplitter>
+#include <QTableWidget>
 #include <QToolButton>
+#include <QTreeView>
 #include <QWizardPage>
-#include <QComboBox>
-#include <QStackedWidget>
+
 
 HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle )
 : HYDROGUI_Wizard( theModule, theTitle )
@@ -75,16 +84,30 @@ HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg()
 void HYDROGUI_CalculationDlg::reset()
 {
   myObjectName->clear();
-  myGeomObjects->clear();
+  HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
+  myGeomObjects->setObjects(anObject2VisibleList);
   myPolylineName->clear();
   myAvailableGeomObjects->clear();
+
+  // Activate the automatic mode
+  setMode( HYDROData_CalculationCase::AUTOMATIC );
+
+  // Reset the priority widget state
+  QList<Handle(HYDROData_Object)> anObjects;
+  myPriorityWidget->setObjects( anObjects );
 }
 
 QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
   QWizardPage* aPage = new QWizardPage( mainFrame() );
   QFrame* aFrame = new QFrame( aPage );
 
-  // Calculation name
+  // Splitter
+  mySplitter = new QSplitter(Qt::Vertical);
+
+  // Top of the page
+  QWidget* aTopContainer = new QWidget;
+   
+  // calculation name
   myObjectName = new QLineEdit( aPage );
   myValidator = new HYDROGUI_NameValidator(module(), myObjectName);
   myObjectName->setValidator( myValidator );
@@ -92,32 +115,49 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
   connect( myValidator, SIGNAL( emptyName() ), SLOT( onEmptyName() ) );
   connect( myValidator, SIGNAL( alreadyExists( QString ) ), SLOT( onAlreadyExists( QString ) ) );
 
+  // polyline name
   myPolylineName = new QComboBox( aPage );
   connect( myPolylineName, SIGNAL( activated( const QString & ) ), 
     SIGNAL( boundarySelected( const QString & ) ) );
 
-  myGeomObjects = new QListWidget( aPage );
-  myGeomObjects->setSelectionMode( QListWidget::ExtendedSelection );
-  myGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
-  myGeomObjects->setViewMode( QListWidget::ListMode );
-  myGeomObjects->setSortingEnabled( true );
+  // names labels
+  QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
+  QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage );
+
+  // mode selector (auto/manual)
+  QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) );
 
+  QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() );
+  QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() );
+
+  myModeButtons = new QButtonGroup( mainFrame() );
+  myModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC );
+  myModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL );
+  
+  QBoxLayout* aModeSelectorLayout = new QHBoxLayout;
+  aModeSelectorLayout->setMargin( 5 );
+  aModeSelectorLayout->setSpacing( 5 );
+  aModeSelectorLayout->addWidget( anAutoRB );
+  aModeSelectorLayout->addWidget( aManualRB );
+  aModeGroup->setLayout( aModeSelectorLayout );
+
+  // geometry objects
+  QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ) );
+  myGeomObjects = new HYDROGUI_OrderedListWidget( aPage, 16 );
+  myGeomObjects->setHiddenObjectsShown(true);
+  myGeomObjects->setVisibilityIconShown(false);
+  myGeomObjects->setContentsMargins(QMargins());
+  // included geometry objects
+  QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ) );
   myAvailableGeomObjects = new QListWidget( aPage );
   myAvailableGeomObjects->setSelectionMode( QListWidget::ExtendedSelection );
   myAvailableGeomObjects->setEditTriggers( QListWidget::NoEditTriggers );
   myAvailableGeomObjects->setViewMode( QListWidget::ListMode );
   myAvailableGeomObjects->setSortingEnabled( true );
 
-  connect( myGeomObjects, SIGNAL( itemSelectionChanged() ), 
-    SIGNAL( objectsSelected() ) );
-
-  QFrame* anObjectsFrame = new QFrame( aPage );
-  QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame );
-  anObjsLayout->setMargin( 5 );
-  anObjsLayout->setSpacing( 5 );
-  anObjectsFrame->setLayout( anObjsLayout );
-
-  QFrame* aBtnsFrame = new QFrame( anObjectsFrame );
+  // buttons
+  QFrame* aBtnsFrame = new QFrame;
   QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
   aBtnsLayout->setMargin( 5 );
   aBtnsLayout->setSpacing( 5 );
@@ -125,41 +165,82 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() {
   QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
   QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
 
-  // Fill the butons frame with two buttons
+  // fill the butons frame with two buttons
   aBtnsLayout->addWidget( anAddBtn );
   aBtnsLayout->addWidget( aRemoveBtn );
   aBtnsLayout->addStretch( 1 );
-
-  QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ), anObjectsFrame );
-  QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ), anObjectsFrame );
-
-  // Fill the objects frame with two lists, two labels and with buttons frame
+  
+  // top of the page layout
+  
+  // objects frame
+  QFrame* anObjectsFrame = new QFrame( aPage );
+  anObjectsFrame->setFrameStyle( QFrame::Panel | QFrame::Raised );
+  QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame );
+  anObjsLayout->setMargin( 5 );
+  anObjsLayout->setSpacing( 5 );
+  anObjectsFrame->setLayout( anObjsLayout );
+  
+  // fill the objects frame with two lists, two labels and with buttons frame
   anObjsLayout->addWidget( anObjectsLabel, 0, 0, Qt::AlignHCenter );
   anObjsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
-  anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0, Qt::AlignHCenter );
+  anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0 );
   anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
-  anObjsLayout->addWidget( myGeomObjects, 1, 2, Qt::AlignHCenter );
-
-
-  QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage );
-  QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage );
-
-  // Fill the page
-  QGridLayout* aPageLayout = new QGridLayout( aPage );
+  anObjsLayout->addWidget( myGeomObjects, 1, 2 );
+  
+  // fill the top of the page
+  QGridLayout* aTopLayout = new QGridLayout;
+  aTopLayout->setMargin( 5 );
+  aTopLayout->setSpacing( 5 );
+  aTopLayout->setVerticalSpacing( 10 );
+  aTopLayout->addWidget( aNameLabel,     0, 0, Qt::AlignHCenter );
+  aTopLayout->addWidget( myObjectName,   0, 1 );
+  aTopLayout->addWidget( aLimitsLabel,   1, 0, Qt::AlignHCenter );
+  aTopLayout->addWidget( myPolylineName, 1, 1 );
+  aTopLayout->addWidget( aModeGroup, 2, 0, 1, 2 );
+  aTopLayout->addWidget( anObjectsFrame, 3, 0, 1, 2 );
+
+  aTopContainer->setLayout( aTopLayout );
+
+  // add the top of the page to the splitter
+  mySplitter->insertWidget(0, aTopContainer);
+  mySplitter->setStretchFactor(0, 2);
+
+  // Bottom of the page
+  myPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() );
+
+  QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) );
+  QBoxLayout* aPriorityLayout = new QHBoxLayout;
+  aPriorityLayout->setMargin( 5 );
+  aPriorityLayout->setSpacing( 5 );
+  aPriorityLayout->addWidget( myPriorityWidget );
+  aPriorityGroup->setLayout( aPriorityLayout );
+
+  // add the bottom of the page to the splitter
+  mySplitter->insertWidget(1, aPriorityGroup);
+  mySplitter->setStretchFactor(1, 1);
+
+  // Page layout
+  QVBoxLayout* aPageLayout = new QVBoxLayout;
   aPageLayout->setMargin( 5 );
   aPageLayout->setSpacing( 5 );
-  aPageLayout->setVerticalSpacing( 10 );
-  aPageLayout->addWidget( aNameLabel,     0, 0, Qt::AlignHCenter );
-  aPageLayout->addWidget( myObjectName,   0, 1 );
-  aPageLayout->addWidget( aLimitsLabel,   1, 0, Qt::AlignHCenter );
-  aPageLayout->addWidget( myPolylineName, 1, 1 );
-  aPageLayout->addWidget( anObjectsFrame, 2, 0, 1, 2, Qt::AlignHCenter );
+  aPageLayout->addWidget( mySplitter );
 
   aPage->setLayout( aPageLayout );
 
+  // Create selector
+  if ( module() ) {
+    HYDROGUI_ListSelector* aListSelector = 
+      new HYDROGUI_ListSelector( myGeomObjects, module()->getApp()->selectionMgr() );
+    aListSelector->setAutoBlock( true );
+  }
+
+  // Connections
+  connect( myModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeMode( int ) ) );
   connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addObjects() ) );
   connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeObjects() ) );
 
+  connect( myGeomObjects, SIGNAL( orderChanged() ), SLOT( onOrderChanged() ) );
+
   return aPage;
 }
 
@@ -207,16 +288,16 @@ QWizardPage* HYDROGUI_CalculationDlg::createGroupsPage() {
   // Fill the objects frame with two lists, two labels and with buttons frame
   aGroupsLayout->addWidget( anAvailableLabel, 0, 0, Qt::AlignHCenter );
   aGroupsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter );
-  aGroupsLayout->addWidget( myAvailableGroups, 1, 0, Qt::AlignHCenter );
+  aGroupsLayout->addWidget( myAvailableGroups, 1, 0 );
   aGroupsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter );
-  aGroupsLayout->addWidget( myGroups, 1, 2, Qt::AlignHCenter );
+  aGroupsLayout->addWidget( myGroups, 1, 2 );
 
   // Fill the page
   QGridLayout* aPageLayout = new QGridLayout( aPage );
   aPageLayout->setMargin( 5 );
   aPageLayout->setSpacing( 5 );
   aPageLayout->setVerticalSpacing( 10 );
-  aPageLayout->addWidget( aGroupsFrame, 0, 0, Qt::AlignHCenter );
+  aPageLayout->addWidget( aGroupsFrame, 0, 0 );
 
   aPage->setLayout( aPageLayout );
 
@@ -239,13 +320,13 @@ QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() {
 
   aLayout->addWidget( myBrowser, 0, 0, 1, 2 );
 
-  myBatimetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
+  myBathymetryLabel = new QLabel( tr( "BATHYMETRY" ), aFrame );
   myBathymetryChoice = new QComboBox( aFrame );
 
   myBathymetryChoice->setVisible( false );
-  myBatimetryLabel->setVisible( false );
+  myBathymetryLabel->setVisible( false );
 
-  aLayout->addWidget( myBatimetryLabel, 1, 0 );
+  aLayout->addWidget( myBathymetryLabel, 1, 0 );
   aLayout->addWidget( myBathymetryChoice, 1, 1 );
 
   aPage->setLayout( aLayout );
@@ -266,7 +347,7 @@ bool HYDROGUI_CalculationDlg::acceptCurrent() const
 {
   QString anErrorMsg;
 
-  if ( myGeomObjects->count() == 0 )
+  if ( false /*myGeomObjects->count() == 0*/ )
   {
     anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" );
   }
@@ -382,7 +463,8 @@ void HYDROGUI_CalculationDlg::onSelected( SUIT_DataObject* theObject )
   }
 
   myBathymetryChoice->setVisible( doShow );
-  myBatimetryLabel->setVisible( doShow );
+  myBathymetryChoice->setEnabled( getMode() == HYDROData_CalculationCase::MANUAL );
+  myBathymetryLabel->setVisible( doShow );
 }
 
 void HYDROGUI_CalculationDlg::setObjectName( const QString& theName )
@@ -418,12 +500,39 @@ void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList&
 
 void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects )
 {
-  moveItems( myAvailableGeomObjects, myGeomObjects, theObjects );
+  HYDROGUI_ListModel::Object2VisibleList anObjectsToInclude;
+  QList<QListWidgetItem*> aFoundItems;
+  foreach ( const QString& anObjName, theObjects ) {
+    // Hide the object in the available objects list
+    aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
+    foreach ( QListWidgetItem* anItem, aFoundItems ) {
+      anItem->setHidden( true );
+    }
+
+    // Add the object to the list of included objects
+    Handle(HYDROData_Entity) anObject = 
+      HYDROGUI_Tool::FindObjectByName( module(), anObjName );
+    myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
+  }
+
+  myPriorityWidget->setObjects( getGeometryObjects() );
 }
 
 void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects )
 {
-  moveItems( myGeomObjects, myAvailableGeomObjects, theObjects );
+  QList<QListWidgetItem*> aFoundItems;
+  foreach ( const QString& anObjName, theObjects ) {
+    // Set visible the object in the available objects list
+    aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly );
+    foreach ( QListWidgetItem* anItem, aFoundItems ) {
+      anItem->setHidden( false );
+    }
+
+    // Remove the object from the list of included objects
+    myGeomObjects->removeObjectByName( anObjName );
+  }
+
+  myPriorityWidget->setObjects( getGeometryObjects() );
 }
 
 void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName )
@@ -470,7 +579,12 @@ QStringList getSelected( QListWidget* theWidget )
 
 QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const
 {
-  return getSelected( myGeomObjects );
+  return myGeomObjects->getSelectedNames();
+}
+
+QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const
+{
+  return myGeomObjects->getAllNames();
 }
 
 QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const
@@ -491,7 +605,6 @@ void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_Calculatio
   myBrowser->adjustColumnsWidth();
   myBrowser->setAutoUpdate( true );
   myBrowser->setUpdateModified( true );
-
 }
 
 HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const
@@ -541,3 +654,87 @@ void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects )
 {
   moveItems( myGroups, myAvailableGroups, theObjects );
 }
+
+/**
+  Get creation mode.
+  @param theMode the mode
+*/
+int HYDROGUI_CalculationDlg::getMode() const
+{
+  return myModeButtons->checkedId();
+}
+
+/**
+  Set creation mode.
+  @param theMode the mode
+*/
+void HYDROGUI_CalculationDlg::setMode( int theMode )
+{
+  bool isBlocked = myModeButtons->blockSignals( true );
+  myModeButtons->button( theMode )->setChecked( true );
+  myModeButtons->blockSignals( isBlocked );
+
+  bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC );
+
+  myGeomObjects->setOrderingEnabled( isAuto );
+  QWidget* aWidget = mySplitter->widget( 1 );
+  if ( aWidget ) {
+    aWidget->setVisible( isAuto );
+  }
+}
+
+/**
+  Enable/disable zones drag'n'drop and renaming.
+  @param theIsEnabled if true - zones drag'n'drop and renaming will be enabled
+*/
+void HYDROGUI_CalculationDlg::setEditZonesEnabled( const bool theIsEnabled )
+{
+  myBrowser->setReadOnly( !theIsEnabled );
+}
+
+/**
+  Get included geometry objects.
+  @return the list of geometry objects
+ */
+QList<Handle(HYDROData_Object)> HYDROGUI_CalculationDlg::getGeometryObjects()
+{
+  QList<Handle(HYDROData_Entity)> anEntities = myGeomObjects->getObjects();
+  QList<Handle(HYDROData_Object)> anObjects;
+
+  foreach ( Handle(HYDROData_Entity) anEntity, anEntities ) {
+    Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anEntity );
+    if ( anObj.IsNull() ) {
+      continue;
+    }
+
+    anObjects << anObj;
+  }
+
+  return anObjects;
+}
+
+/**
+  Get rules.
+  @return the list of rules
+ */
+HYDROData_ListOfRules HYDROGUI_CalculationDlg::getRules() const
+{
+  return myPriorityWidget->getRules();
+}
+
+/**
+  Set rules.
+  @param theRules the list of rules
+ */
+void  HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) const
+{
+  myPriorityWidget->setRules( theRules );
+}
+
+/**
+  Slot called when objects order is changed.
+ */
+void HYDROGUI_CalculationDlg::onOrderChanged()
+{
+  myPriorityWidget->setObjects( getGeometryObjects() );
+}
\ No newline at end of file
index eaf3aa26aa6a52a2e81a437d88753c6953b79619..5010b7d2cba7d697f1d04e205935d4ff4767c4c1 100644 (file)
 #include <HYDROData_CalculationCase.h>
 
 class HYDROGUI_ObjSelector;
+class HYDROGUI_DataBrowser;
+class HYDROGUI_NameValidator;
+class HYDROGUI_Zone;
+class HYDROGUI_OrderedListWidget;
+class HYDROGUI_PriorityWidget;
+
+class SUIT_DataObject;
+
+class QButtonGroup;
 class QGroupBox;
 class QLineEdit;
 class QListWidget;
 class QComboBox;
 class QLabel;
+class QSplitter;
 class QStringList;
-class HYDROGUI_DataBrowser;
-class HYDROGUI_NameValidator;
-class SUIT_DataObject;
-class HYDROGUI_Zone;
+
 
 class HYDROGUI_CalculationDlg : public HYDROGUI_Wizard
 {
@@ -48,22 +55,31 @@ public:
 
   void                       reset();
 
+  int                        getMode() const;
+
   void                       setObjectName( const QString& theName );
   QString                    getObjectName() const;
 
   void                       setEditedObject( const Handle(HYDROData_CalculationCase) theCase );
 
   void                       setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries );
+  QStringList                getAllGeomObjects() const;
   void                       setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries );
   QStringList                getSelectedGeomObjects() const;
   QStringList                getSelectedAvailableGeomObjects() const;
   QStringList                getSelectedGroups() const;
   QStringList                getSelectedAvailableGroups() const;
   HYDROGUI_Zone*             getCurrentZone() const;
-
+  
   void                       setAvailableGroups( const QStringList& );
 
+  void                       setEditZonesEnabled( const bool theIsEnabled );
+
+  HYDROData_ListOfRules      getRules() const;
+  void                       setRules( const HYDROData_ListOfRules& theRules ) const;
+
 public slots:
+  void                       setMode( int theMode );
   void                       setBoundary( const QString& theObjName );
   void                       includeGeomObjects( const QStringList& theObjects );
   void                       excludeGeomObjects( const QStringList& theObjects );
@@ -73,6 +89,8 @@ public slots:
   void                       onAlreadyExists( QString theName );
   void                       refreshZonesBrowser();
   void                       onDataChanged();
+  void                       onOrderChanged();
+
   /**
    * Process items selection: hide/show bathymetry merge type selector.
    */
@@ -88,6 +106,8 @@ public slots:
     SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction );
 
 signals:
+  void                       changeMode( int theMode );
+
   void                       addObjects();
   void                       removeObjects();
   void                       objectsSelected();
@@ -107,19 +127,26 @@ protected:
   virtual bool               acceptCurrent() const;
 
 private:
+  QList<Handle(HYDROData_Object)> getGeometryObjects();
 
   QWizardPage*               createObjectsPage();
   QWizardPage*               createGroupsPage();
   QWizardPage*               createZonesPage();
 
+  QSplitter*                 mySplitter;
+
   QGroupBox*                 myObjectNameGroup;
   QLineEdit*                 myObjectName;
   HYDROGUI_NameValidator*    myValidator;
 
   QComboBox*                 myPolylineName;
 
+  QButtonGroup*              myModeButtons;
+
   QListWidget*               myAvailableGeomObjects;
-  QListWidget*               myGeomObjects;
+  HYDROGUI_OrderedListWidget* myGeomObjects;
+
+  HYDROGUI_PriorityWidget*   myPriorityWidget;
 
   QListWidget*               myAvailableGroups;
   QListWidget*               myGroups;
@@ -127,7 +154,7 @@ private:
   HYDROGUI_DataBrowser*      myBrowser;
   Handle(HYDROData_CalculationCase) myEditedObject;
   QComboBox*                 myBathymetryChoice;
-  QLabel*                    myBatimetryLabel;
+  QLabel*                    myBathymetryLabel;
   HYDROGUI_Zone*             myCurrentZone;
 };
 
index f3b4351c607bce16219f2ef9ff3731a3ef84cdce..898a3c1e64232536e08b267a9ff9379c20ea8d1f 100644 (file)
@@ -133,6 +133,7 @@ void HYDROGUI_CalculationOp::startOperation()
     myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
     if ( !myEditedObject.IsNull() )
     {
+      aPanel->setMode( myEditedObject->GetAssignmentMode() );
       anObjectName = myEditedObject->GetName();
       aPolylineObj = myEditedObject->GetBoundaryPolyline();
       if ( aPolylineObj.IsNull() )
@@ -148,13 +149,35 @@ void HYDROGUI_CalculationOp::startOperation()
       aSeq = myEditedObject->GetGeometryObjects();
       getNamesAndEntries( aSeq, aList, anEntryList );
       aPanel->includeGeomObjects( aList );
+
+      // set rules
+      HYDROData_ListOfRules aRules;
+      Handle(HYDROData_Object) anObject1, anObject2;
+      HYDROData_PriorityType aPriority;
+      HYDROData_Zone::MergeAltitudesType aMergeType;
+      for ( int anIndex = 0; ; anIndex++ )
+      {
+        if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType ) ) {
+          HYDROData_CustomRule aRule;
+          aRule.Object1 = anObject1;
+          aRule.Object2 = anObject2;
+          aRule.Priority = aPriority;
+          aRule.MergeType = aMergeType;
+
+          aRules << aRule;
+        }
+        else
+          break;
+      }
+      aPanel->setRules( aRules );
     }
   }
   else
   {
     myEditedObject =
       Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
-    myEditedObject->SetName(anObjectName);
+    myEditedObject->SetName( anObjectName );
+    myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
   }
 
   aPanel->setObjectName( anObjectName );
@@ -203,6 +226,7 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
   HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
 
   // Connect signals and slots
+  connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
   connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
   connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
   connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
@@ -485,7 +509,32 @@ bool HYDROGUI_CalculationOp::confirmRegionsChange() const
       // If there are already defined zones then ask a user to confirm zones recalculation
       isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
                                tr( "REGIONS_CHANGED" ),
-                               tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION" ),
+                               tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
+                               QMessageBox::Yes | QMessageBox::No,
+                               QMessageBox::No ) == QMessageBox::Yes );
+    }
+    else
+    {
+      isConfirmed = true; // No regions - no zones - nothing to recalculate
+    }
+  }
+  return isConfirmed;
+}
+
+bool HYDROGUI_CalculationOp::confirmModeChange() const
+{
+  // Check if the case is already modified or not
+  bool isConfirmed = myEditedObject->IsMustBeUpdated();
+  if ( !isConfirmed )
+  {
+    // If not modified check if the case has already defined regions with zones
+    HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
+    if ( aSeq.Length() > 0 )
+    {
+      // If there are already defined zones then ask a user to confirm zones recalculation
+      isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
+                               tr( "MODE_CHANGED" ),
+                               tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
                                QMessageBox::Yes | QMessageBox::No,
                                QMessageBox::No ) == QMessageBox::Yes );
     }
@@ -497,6 +546,35 @@ bool HYDROGUI_CalculationOp::confirmRegionsChange() const
   return isConfirmed;
 }
 
+bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
+{
+  HYDROData_WarningType aType = theWarning.Type;
+  if ( aType == WARN_OK ) {
+    return true;
+  }
+
+  QString aTitle;
+  QString aMsg;
+  switch ( aType )
+  {
+    case WARN_EMPTY_REGIONS:
+      aTitle = tr( "EMPTY_REGIONS" );
+      aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
+      break;
+    default:
+      aTitle = tr( "WARNING" );
+      aMsg = theWarning.Data;
+  }
+
+
+  int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
+                                           aTitle, aMsg,
+                                           QMessageBox::Yes | QMessageBox::No,
+                                           QMessageBox::No );
+
+  return ( anAnswer == QMessageBox::Yes );
+}
+
 bool HYDROGUI_CalculationOp::processApply( int&     theUpdateFlags,
                                            QString& theErrorMsg,
                                            QStringList& theBrowseObjectsEntries )
@@ -512,6 +590,11 @@ bool HYDROGUI_CalculationOp::processApply( int&     theUpdateFlags,
     theBrowseObjectsEntries.append( anEntry );
   }
 
+  // For manual mode priority rules are redundant
+  if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
+    myEditedObject->ClearRules( false );
+  }
   theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
 
   return true;
@@ -519,6 +602,20 @@ bool HYDROGUI_CalculationOp::processApply( int&     theUpdateFlags,
 
 void HYDROGUI_CalculationOp::onApply()
 {
+  // Check warnings
+  HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
+  if ( aWarning.Type != WARN_OK ) {
+    if ( !confirmContinueWithWarning( aWarning ) ) {
+      // Go back to the first page
+      HYDROGUI_CalculationDlg* aPanel = 
+        ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+      if ( aPanel ) {
+        aPanel->onFirstPage();
+      }
+      return;
+    }
+  }
+
   QApplication::setOverrideCursor( Qt::WaitCursor );
 
   int anUpdateFlags = 0;
@@ -579,30 +676,69 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex )
   
     QString aNewCaseName = aPanel->getObjectName();
     QString anOldCaseName = myEditedObject->GetName();
+    bool isNameChanged = anOldCaseName != aNewCaseName;
   
-    bool anIsToUpdateOb = myIsEdit && anOldCaseName != aNewCaseName;
-  
+    bool anIsToUpdateOb = isNameChanged;
+
     // At first we must to update the case name because of 
     // automatic names generation for regions and zones
     myEditedObject->SetName( aNewCaseName );
-  
+    
+    // Set parameters for automatic mode
+    int aMode = aPanel->getMode();
+    if ( aMode == HYDROData_CalculationCase::AUTOMATIC ) {
+      // Set objects in the specified order
+      myEditedObject->RemoveGeometryObjects();
+      foreach ( const QString& aName, aPanel->getAllGeomObjects() ) {
+        Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast( 
+          HYDROGUI_Tool::FindObjectByName( module(), aName ) );
+        if ( anObject.IsNull() ) {
+          continue;
+        }
+
+        myEditedObject->AddGeometryObject( anObject );
+      }
+
+      // Clear priority rules
+      //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
+        myEditedObject->ClearRules( true );
+      //@ASL }
+      // Set priority rules
+      foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
+        myEditedObject->AddRule( aRule.Object1, aRule.Priority,
+                                 aRule.Object2, aRule.MergeType );
+      }
+    }
+    aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
+         
     if ( myEditedObject->IsMustBeUpdated() )
     {
       myShowZones = true;
       myEditedObject->Update();
-
+      
       //aPanel->setEditedObject( myEditedObject );
       aPanel->refreshZonesBrowser();
-
+    
+      closePreview();
       createPreview();
+
+      anIsToUpdateOb = true;
     }
     else
     {
       setZonesVisible( true );
+
+      if ( isNameChanged ) {
+        module()->getDataModel()->updateObjectTree( myEditedObject );
+      }
     }
 
-    if ( anIsToUpdateOb )
-      module()->getApp()->updateObjectBrowser( false );
+    if ( anIsToUpdateOb ) {
+      SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
+      if ( anObjBrowser ) {
+        anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
+      }
+    }
 
     QApplication::restoreOverrideCursor();
   }
@@ -880,3 +1016,19 @@ void HYDROGUI_CalculationOp::onRemoveGroups()
 
   aPanel->excludeGroups( aSelectedList );
 }
+
+void HYDROGUI_CalculationOp::onChangeMode( int theMode )
+{
+  HYDROGUI_CalculationDlg* aPanel = 
+    ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+  if ( !aPanel )
+    return;
+
+  if ( !confirmModeChange() ) {
+    aPanel->setMode( myEditedObject->GetAssignmentMode() );
+    return;
+  }
+
+  myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
+  aPanel->setMode( theMode );
+}
index 81c19c61dcd4142c75b9524c964d78be9a09a17f..271bb52d6613d30822d346f3adc439c03dc1ca96 100644 (file)
@@ -58,6 +58,13 @@ protected:
   void setAvailableGroups();
 
 protected slots:
+
+  /**
+   * Change the creation mode.
+   * @param theMode the mode to set
+   */
+  void                            onChangeMode( int theMode );
+
   /**
    * Add geometry objects selected in the module browser to the calculation case.
    */
@@ -120,11 +127,24 @@ private:
                                                       QStringList& theNames, QStringList& theEntries ) const;
 
   /**
-   * Ask user to confirm splitting zones recalculation.
+   * Ask user to confirm splitting zones recalculation after regions list modification.
    * \return true if confirmed
    */
   bool                            confirmRegionsChange() const;
 
+  /**
+   * Ask user to confirm splitting zones recalculation after mode change.
+   * \return true if confirmed
+   */
+  bool                            confirmModeChange() const;
+
+  /**
+   * Ask user to confirm the operation continuation with warning.
+   * @param theWarning the warning
+   * \return true if confirmed
+   */
+  bool                            confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const;
+
 private:
   bool                            myIsEdit;
   bool                            myShowZones;
index d5460b64f0bb1abc31f70d1c963182732c19b45c..86e069df110e0d4393790ea517c2738a67f1274f 100644 (file)
@@ -42,6 +42,7 @@
 #include <SUIT_DataOwner.h>
 
 #include <QObject>
+#include <QShortcut>
 
 class SUIT_DataBrowser;
 class LightApp_DataObject;
@@ -294,3 +295,29 @@ SUIT_DataObject* HYDROGUI_DataBrowser::findObject( const QString& theEntry ) con
   }
   return NULL;
 }
+
+/*!
+  \brief Switch read only mode for the Object Browser.
+  \param theIsReadOnly if true - read only mode will be turned on
+*/
+void HYDROGUI_DataBrowser::setReadOnly( const bool theIsReadOnly )
+{
+  //TODO: to be reimplemented
+
+  // Enable/disable edit triggers
+  foreach ( QTreeView* aView, findChildren<QTreeView*>() ) {
+    aView->setDragEnabled ( !theIsReadOnly );
+    aView->setEditTriggers ( theIsReadOnly ?
+                             QAbstractItemView::NoEditTriggers :
+                             QAbstractItemView::DoubleClicked );
+  }
+
+  // Enable/disable rename shortcut
+  QList<QShortcut*> aShortcuts = findChildren<QShortcut*>();
+  QShortcut* aShortcut;
+  foreach( aShortcut, aShortcuts ) {
+    if ( aShortcut->key() == QKeySequence( shortcutKey( RenameShortcut ) ) ) {
+      aShortcut->setEnabled( !theIsReadOnly );
+    }
+  }
+}
\ No newline at end of file
index 11856cf6352a48de4a750a44e30f66f3761e6773..82620c5bd8836dfb2bab330a935399cfafbaa3bd 100644 (file)
@@ -48,6 +48,8 @@ public:
   */
   virtual SUIT_DataObject* findObject( const QString& ) const;
 
+  void                     setReadOnly( const bool theIsReadOnly ); 
+
 signals:
   void             dropped( const QList<SUIT_DataObject*>& theList, 
     SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction );
index 6f1adada33b9121c81a475262fb6489338014aa0..ee3b3fddb4494278013dc025751323a3e1981d45 100644 (file)
@@ -453,7 +453,9 @@ void HYDROGUI_DataModel::update( const int theStudyId )
 
 HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject )
 {
-  return NULL; // to do if necessary
+  HYDROGUI_DataObject* aGuiObj = dynamic_cast<HYDROGUI_DataObject*>(
+    findObject( HYDROGUI_DataObject::dataObjectEntry( theModelObject ) ) );
+  return aGuiObj;
 }
 
 HYDROGUI_DataObject* HYDROGUI_DataModel::getReferencedDataObject( HYDROGUI_DataObject* theObject )
index 9701970ad2ee07bfdeae4a3e043341e1d861ba24..6f2b9cce804d3d8f228b441f0556bd33cc35ad12 100644 (file)
@@ -234,11 +234,6 @@ void HYDROGUI_DataObject::updateBy( SUIT_DataObject* theObj )
   setModified( true );
 }
 
-
-
-
-
-
 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
                                             const QString&   theName,
                                             const QString&   theParentEntry,
index d91522bbe093b1b6dc28b9f2b7e710c037949675..f5128a9b1df2befd1c3f40b208d3e77329a9de69 100644 (file)
@@ -91,7 +91,8 @@ bool HYDROGUI_ExportCalculationOp::processApply( int& theUpdateFlags,
   if ( aStudy ) {
     SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy->studyDS() );
     GEOM::GEOM_Gen_var aGeomEngine = GeometryGUI::GetGeomGen();
-    if ( aCalculation->Export( aGeomEngine, aDSStudy ) ) {
+    QString anEntry;
+    if ( aCalculation->Export( aGeomEngine, aDSStudy, anEntry ) ) {
       theUpdateFlags = UF_ObjBrowser;
       isOk = true;
     }
index 24e3fe8f4c556081ea468174a5aeadf2f3864541..e6deaf424f59039bb74062064f55339eddb091e4 100644 (file)
@@ -37,7 +37,7 @@ const QString OBJ_LIST_MIME_TYPE = "application/hydro.objects.list";
   @param theParent the parent object
 */
 HYDROGUI_ListModel::HYDROGUI_ListModel( QObject* theParent )
- : QAbstractListModel( theParent )
+ : QAbstractListModel( theParent ), myIsDecorationEnabled( true )
 {
   // Get resource manager
   SUIT_ResourceMgr* aResMgr = 0;
@@ -89,8 +89,8 @@ QVariant HYDROGUI_ListModel::data( const QModelIndex &theIndex, int theRole ) co
 
   case Qt::DecorationRole:
     {
-      if( aColumn==0 && aRow >=0 && aRow < myObjects.count() )
-      {
+      if( myIsDecorationEnabled && 
+          aColumn==0 && aRow >=0 && aRow < myObjects.count() ) {
         bool isVisible = isObjectVisible( aRow );
         if( isVisible )
           return myEye;
@@ -152,6 +152,36 @@ HYDROGUI_ListModel::ObjectList HYDROGUI_ListModel::getObjects() const
   return anObjects;
 }
 
+/**
+  Add the object to the end of the list.
+  @param theObjects the pair (object; visibility)
+*/
+void HYDROGUI_ListModel::addObject( const Object2Visible& theObject )
+{
+  myObjects << theObject;
+
+  reset();
+}
+
+/**
+  Remove the object from the list.
+  @param theObjectName the name of the object to remove
+*/
+void HYDROGUI_ListModel::removeObjectByName( const QString& theObjectName )
+{
+  Object2Visible anItem;
+  foreach( anItem, myObjects ) {
+    if ( anItem.first->GetName() == theObjectName ) {
+      break;
+    }
+  }
+
+  myObjects.removeAll(anItem);
+
+  reset();
+}
+
+
 /**
   Check if the object is visible.
   @param theIndex the object index
@@ -453,3 +483,12 @@ bool HYDROGUI_ListModel::isDragAndDropAllowed( const QList<int>& theItems,
 
   return isAllowed;
 }
+
+/**
+  Enable/disable decoration (eye icon).
+  @param theIsToEnable if true - the decoration will be enabled
+*/
+void HYDROGUI_ListModel::setDecorationEnabled( const bool theIsToEnable )
+{
+  myIsDecorationEnabled = theIsToEnable;
+}
\ No newline at end of file
index 12ca7f712b8a3141bc4c353cafa0d5cc00b3be39..ea65f808469440406b02ae02aad91c8775b5e9ff 100644 (file)
@@ -69,11 +69,16 @@ public:
   void setObjects( const Object2VisibleList& theObjects );
   ObjectList getObjects() const;
 
+  void addObject( const Object2Visible& theObject );
+  void removeObjectByName( const QString& theObjectName );
+
   bool move( const int theItem, const OpType theType, bool theIsVisibleOnly,
              const int theDropItem = -1 );
   bool move( const QList<int>& theItems, const OpType theType, bool theIsVisibleOnly,
              const int theDropItem = -1 );
 
+  void setDecorationEnabled( const bool theIsToEnable );
+
 protected:
   bool isObjectVisible( int theIndex ) const;
   bool isDragAndDropAllowed( const QList<int>& theItems, const int theDropItem ) const;
@@ -83,6 +88,8 @@ private:
 
   Object2VisibleList myObjects;
   QPixmap myEmpty, myEye;
+
+  bool myIsDecorationEnabled;
 };
 
 #endif
\ No newline at end of file
index 51e6c30398a76f7f635142942a946817eda3fc89..e46e0cd97f70df8f1570080c20b706df2bcf1cf1 100644 (file)
@@ -259,6 +259,12 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
   myVTKPrsMap.clear();
   */
 
+  // clear the status bar
+  SUIT_Desktop* aDesktop = getApp()->desktop();
+  if ( aDesktop && aDesktop->statusBar() ) {
+    aDesktop->statusBar()->clearMessage();
+  }
+
   // clear the data model's list of copying objects
   HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() );
 
index 1308378ffa1ccc2285c6abcf5ec53dfc4105d663..8c23d22407f6d6e66af11030f07b6232f1d92615 100644 (file)
 /**
   Constructor.
   @param theParent the parent widget
+  @param theIconSize the icon size for arrow buttons
 */
-HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent )
+HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent, int theArrowIconSize )
 : QWidget( theParent )
 {
   // Main layout
   QHBoxLayout* aMainLayout = new QHBoxLayout( this );
+  aMainLayout->setMargin( 0 );
   aMainLayout->setSpacing( 5 );
 
   // List view
@@ -68,7 +70,7 @@ HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent )
   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
   myTop = new QPushButton( this );
   myTop->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_TOP_ICO" ) ) );
-  myTop->setIconSize( QSize( 32, 32 ) );
+  myTop->setIconSize( QSize( theArrowIconSize, theArrowIconSize ) );
   myTop->setToolTip( tr( "TOP_TLT" ) );
   myUp = new QPushButton( this );
   myUp->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_UP_ICO" ) ) );
@@ -112,6 +114,7 @@ HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent )
 
   // Initialize
   setHiddenObjectsShown( true );
+  setVisibilityIconShown( true );
 }
 
 /**
@@ -149,6 +152,30 @@ QList<Handle(HYDROData_Entity)> HYDROGUI_OrderedListWidget::getObjects() const
   return anObjects;
 }
 
+/**
+  Add the object to the end of the list.
+  @param theObjects the pair (object; visibility)
+*/
+void HYDROGUI_OrderedListWidget::addObject( const HYDROGUI_ListModel::Object2Visible& theObject )
+{
+  HYDROGUI_ListModel* aModel = getSourceModel();
+  if( aModel ) {
+    aModel->addObject(theObject);
+  }
+}
+
+/**
+  Remove the object from the list.
+  @param theObjectName the name of the object to remove
+*/
+void HYDROGUI_OrderedListWidget::removeObjectByName( const QString& theObjectName )
+{
+  HYDROGUI_ListModel* aModel = getSourceModel();
+  if( aModel ) {
+    aModel->removeObjectByName(theObjectName);
+  }
+}
+
 /**
   Set whether the hidden objects are presented in the list.
   @param theIsToShow if true - the hidden objects will be shown in the list
@@ -162,6 +189,18 @@ void HYDROGUI_OrderedListWidget::setHiddenObjectsShown( const bool theIsToShow )
   aFilterModel->setFilterRegExp( anExpr );
 }
 
+/**
+  Set whether the visibility icon (eye icon) are presented in the list.
+  @param theIsToShow if true - the eye icon will be shown in the list
+*/
+void HYDROGUI_OrderedListWidget::setVisibilityIconShown( const bool theIsToShow )
+{
+  HYDROGUI_ListModel* aModel = getSourceModel();
+  if( aModel ) {
+    aModel->setDecorationEnabled( theIsToShow );
+  }
+}
+
 /**
   Get entries of the selected objects.
   @return the list of entries
@@ -223,12 +262,56 @@ void HYDROGUI_OrderedListWidget::setSelectedEntries( const QStringList& theEntri
   }
 }
 
+/**
+  Get names of the selected objects.
+  @return the list of names
+*/
+QStringList HYDROGUI_OrderedListWidget::getSelectedNames() const
+{
+  QStringList aNames;
+
+  QSortFilterProxyModel* aFilterModel = 
+    dynamic_cast<QSortFilterProxyModel*>( myList->model() );
+  if ( aFilterModel ) {
+    HYDROGUI_ListModel* aSourceModel = 
+      dynamic_cast<HYDROGUI_ListModel*>( aFilterModel->sourceModel() );
+    if ( aSourceModel ) {
+      QModelIndexList aSelectedIndexes = myList->selectionModel()->selectedIndexes();
+      foreach ( const QModelIndex& anIndex, aSelectedIndexes ) {
+        QModelIndex aSourceIndex = aFilterModel->mapToSource( anIndex );
+        QString anEntry = aSourceModel->data( aSourceIndex, Qt::DisplayRole ).toString();
+        aNames << anEntry;
+      }
+    }
+  }
+
+  return aNames;
+}
+
+/**
+  Get names of all objects.
+  @return the list of names
+*/
+QStringList HYDROGUI_OrderedListWidget::getAllNames() const
+{
+  QStringList aNames;
+
+
+  foreach ( const Handle(HYDROData_Entity)& anObject, getObjects() ) {
+    aNames << anObject->GetName();
+  }
+
+  return aNames;
+}
+
 /**
   Slot called on top, up, down and bottom button click.
   @param theType the move operation type
 */
 void HYDROGUI_OrderedListWidget::onMove( int theType )
 {
+  bool isMoved = false;
+
   QSortFilterProxyModel* aFilterModel = dynamic_cast<QSortFilterProxyModel*>( myList->model() );
   if( aFilterModel ) {
     HYDROGUI_ListModel* aModel = dynamic_cast<HYDROGUI_ListModel*>( aFilterModel->sourceModel() );
@@ -239,10 +322,14 @@ void HYDROGUI_OrderedListWidget::onMove( int theType )
         aSelectedSourceIndexes << aFilterModel->mapToSource( anIndex );
       }
       QList<int> aSelectedIds = aModel->getIds( aSelectedSourceIndexes );
-      aModel->move( aSelectedIds, ( HYDROGUI_ListModel::OpType )theType, 
-                    !myIsHiddenObjectsShown );      
+      isMoved = aModel->move( aSelectedIds, ( HYDROGUI_ListModel::OpType )theType, 
+                              !myIsHiddenObjectsShown );
     }
   }
+
+  if ( isMoved ) {
+    emit orderChanged();
+  }
 }
 
 /**
@@ -259,4 +346,20 @@ HYDROGUI_ListModel* HYDROGUI_OrderedListWidget::getSourceModel() const
   }
 
   return aSourceModel;
+}
+
+/**
+  Enable/disable ordering (i.e. enable/disable arrow buttons and drag and drop).
+  @param theIsToEnable if true - ordering will bw enabled
+*/
+void HYDROGUI_OrderedListWidget::setOrderingEnabled( const bool theIsToEnable )
+{
+  // enable/disable arrow buttons
+  myTop->setEnabled( theIsToEnable );
+  myUp->setEnabled( theIsToEnable );
+  myDown->setEnabled( theIsToEnable );
+  myBottom->setEnabled( theIsToEnable );
+
+  // enable/disable drag and drop
+  myList->setDragEnabled( theIsToEnable );
 }
\ No newline at end of file
index e199fb7aae73a05fe3629589e0b122b5cd65a25e..31faba84e5bd73a273e23cd302fb9d1713e2b8ad 100644 (file)
@@ -42,19 +42,29 @@ class HYDRO_EXPORT HYDROGUI_OrderedListWidget : public QWidget
   Q_OBJECT
 
 public:
-  HYDROGUI_OrderedListWidget( QWidget* theParent );
+  HYDROGUI_OrderedListWidget( QWidget* theParent, int theArrowIconSize = 32 );
   virtual ~HYDROGUI_OrderedListWidget();
 
   void setObjects( const HYDROGUI_ListModel::Object2VisibleList& theObjects );
   HYDROGUI_ListModel::ObjectList getObjects() const;
 
+  void addObject( const HYDROGUI_ListModel::Object2Visible& theObject );
+  void removeObjectByName( const QString& theObjectName );
+
   void setHiddenObjectsShown( const bool theIsToShow );
+  void setVisibilityIconShown( const bool theIsToShow );
+
+  void setOrderingEnabled( const bool theIsToEnable );
 
   QStringList getSelectedEntries() const;
   void setSelectedEntries( const QStringList& theEntries ) const;
 
+  QStringList getSelectedNames() const;
+  QStringList getAllNames() const;
+
 signals:
   void selectionChanged();
+  void orderChanged();
 
 private slots:
   void onMove( int theType );
@@ -62,6 +72,8 @@ private slots:
 private:
   HYDROGUI_ListModel* getSourceModel() const;
 
+  QModelIndexList getSelectedIndexes() const;
+
 private:
   QListView*   myList;   ///< the list view
   QPushButton* myTop;    ///< the move on top button
@@ -70,6 +82,7 @@ private:
   QPushButton* myBottom; ///< the move on bottom button
 
   bool myIsHiddenObjectsShown; ///< defines whether to include hidden objects in the list
+  bool myIsVisibilityIconShown; ///< defines whether to show visibility icon (eye icon)
 };
 
 #endif
diff --git a/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx b/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx
new file mode 100644 (file)
index 0000000..6d737e3
--- /dev/null
@@ -0,0 +1,486 @@
+// Copyright (C) 2007-2013  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
+//
+// 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.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_PriorityTableModel.h"
+
+
+/**
+  Constructor.
+  @param theParent the parent object
+*/
+HYDROGUI_PriorityTableModel::HYDROGUI_PriorityTableModel( QObject* theParent )
+ : QAbstractTableModel( theParent )
+{
+}
+
+/**
+  Destructor.
+*/
+HYDROGUI_PriorityTableModel::~HYDROGUI_PriorityTableModel()
+{
+}
+
+/**
+ */
+Qt::ItemFlags  HYDROGUI_PriorityTableModel::flags( const QModelIndex & theIndex ) const
+{
+  return Qt::ItemIsSelectable  | Qt::ItemIsEditable | Qt::ItemIsEnabled;
+}
+
+/**
+ */
+QVariant HYDROGUI_PriorityTableModel::data( const QModelIndex &theIndex, int theRole ) const
+{
+  QVariant aVariant;
+
+  int aRow = theIndex.row();
+  int aColumn = theIndex.column();
+
+  if ( !theIndex.isValid() || aRow > myRules.size() ) {
+    return aVariant;
+  }
+  
+  if ( theRole == Qt::DisplayRole ) {
+    HYDROData_CustomRule aRule = myRules.at(aRow);
+
+    if ( aColumn == 0 ) {
+      aVariant = aRule.Object1->GetName();
+    } else if ( aColumn == 1 ) {
+      aVariant = priorityToString( aRule.Priority );
+    } else if ( aColumn == 2 ) {
+      aVariant = aRule.Object2->GetName();
+    } else if ( aColumn == 3 ) {
+      aVariant = mergeTypeToString( aRule.MergeType );
+    }
+  } else if ( theRole == Qt::EditRole ) {
+    HYDROData_CustomRule aRule = myRules.at(aRow);
+
+    if ( aColumn == 0 ) {
+      aVariant = aRule.Object1->GetName();
+    } else if ( aColumn == 1 ) {
+      aVariant = aRule.Priority;
+    } else if ( aColumn == 2 ) {
+      aVariant = aRule.Object2->GetName();
+    } else if ( aColumn == 3 ) {
+      aVariant = aRule.MergeType;
+    }
+  } else if ( theRole ==  Qt::UserRole ) {
+    if ( aColumn == 0 || aColumn == 2 ) {
+      QStringList aNames;
+      HYDROData_CustomRule aRule = myRules.at( aRow );
+      Handle(HYDROData_Object) aUsedObject = aColumn == 0 ? aRule.Object2 : aRule.Object1;
+      if ( !aUsedObject.IsNull() ) {
+        aNames = getAvailablePairs( aUsedObject );
+      }
+      aVariant = aNames;
+    } else if ( aColumn == 1 ) {
+      QMap<QString, QVariant> aMap;
+      aMap.insert( priorityToString( LESS ), LESS );
+      aMap.insert( priorityToString( GREATER ), GREATER );
+      aVariant = QVariant( aMap );
+    } else if ( aColumn == 3 ) {
+      QMap<QString, QVariant> aMap;
+      aMap.insert( mergeTypeToString( HYDROData_Zone::Merge_Object ), HYDROData_Zone::Merge_Object );
+      aMap.insert( mergeTypeToString( HYDROData_Zone::Merge_ZMIN ), HYDROData_Zone::Merge_ZMIN );
+      aMap.insert( mergeTypeToString( HYDROData_Zone::Merge_ZMAX ), HYDROData_Zone::Merge_ZMAX );
+      aVariant = QVariant( aMap );
+    } 
+  } else if ( theRole == Qt::TextAlignmentRole ) {
+    aVariant = Qt::AlignCenter;
+  }
+
+  return aVariant;
+}
+
+/**
+ */
+bool HYDROGUI_PriorityTableModel::setData( const QModelIndex & theIndex, const QVariant & theValue, int theRole )
+{
+  int aRow = theIndex.row();
+  if ( !theIndex.isValid() || aRow > myRules.size() ) {
+    return false;
+  }
+
+  bool aRes = false;
+
+  if ( theRole ==  Qt::EditRole ) {
+    int aColumn = theIndex.column();
+
+    if ( aColumn == 0 || aColumn == 2 ) {
+      Handle(HYDROData_Object) anObject;
+      QString anObjName = theValue.toString();
+      foreach ( const Handle(HYDROData_Object) anObj, myObjects ) {
+        if ( anObj->GetName() == anObjName ) {
+          anObject = anObj;
+          break;
+        }
+      }
+      if ( !anObject.IsNull() ) {
+        HYDROData_CustomRule anEditedRule = myRules[aRow];
+        
+        if ( aColumn == 0 ) {
+          anEditedRule.Object1 = anObject;
+        } else {
+          anEditedRule.Object2 = anObject;
+        }
+        
+        if ( !isUsed( anEditedRule.Object1, anEditedRule.Object2 ) ) {
+          myRules[aRow] = anEditedRule;
+          aRes = true;
+        } else {
+          emit showError( tr("ALREADY_EXISTS") );
+        }
+      }
+    } else if ( aColumn == 1 ) {
+      myRules[aRow].Priority = (HYDROData_PriorityType)theValue.toInt();
+    } else if ( aColumn == 3 ) {
+      myRules[aRow].MergeType = (HYDROData_Zone::MergeAltitudesType)theValue.toInt();;
+    }
+  }
+
+  return aRes;
+}
+
+/**
+ */
+int HYDROGUI_PriorityTableModel::rowCount( const QModelIndex &theParent ) const
+{
+  return myRules.count();
+}
+
+/**
+ */
+int HYDROGUI_PriorityTableModel::columnCount( const QModelIndex &theParent ) const
+{
+  return 4;
+}
+
+/**
+  Set rules.
+  @param theRules the list of rules
+*/
+void HYDROGUI_PriorityTableModel::setRules( const HYDROData_ListOfRules& theRules )
+{
+  beginResetModel();
+  myRules = theRules;
+  endResetModel();
+}
+
+/**
+  Get rules.
+  @return the list of rules
+*/
+HYDROData_ListOfRules HYDROGUI_PriorityTableModel::getRules() const
+{
+  return myRules;
+}
+
+/**
+*/
+QVariant HYDROGUI_PriorityTableModel::headerData( int theSection,
+                                                  Qt::Orientation theOrientation,
+                                                  int theRole ) const
+{
+  QVariant aData;
+
+  if ( theRole != Qt::DisplayRole ) {
+    return aData;
+  }
+
+  if ( theOrientation == Qt::Horizontal ) {
+    switch( theSection )
+    {
+    case 0:
+      aData = tr( "OBJECT1" );
+      break;
+    case 1:
+      aData = tr( "PRIORITY" );
+      break;
+    case 2:
+      aData = tr( "OBJECT2" );
+      break;
+    case 3:
+      aData = tr( "BATHYMETRY" );
+      break;
+    };
+  } else if ( theOrientation == Qt::Vertical ) {
+    aData = theSection + 1;
+  }
+
+  return aData;
+}
+
+/**
+  Set objects which could be used for rules definition.
+  @param theObjects the ordered list of objects
+ */
+void HYDROGUI_PriorityTableModel::setObjects( const QList<Handle(HYDROData_Object)>& theObjects )
+{
+  myObjects = theObjects;
+    
+  beginResetModel();
+
+  // Remove rules which use objects which are no longer available
+  QStringList aNames = getAvailableObjectNames();
+  QMutableListIterator<HYDROData_CustomRule> anIter( myRules );
+  while ( anIter.hasNext() ) {
+    HYDROData_CustomRule aRule = anIter.next();
+     if ( !aNames.contains( aRule.Object1->GetName() ) || 
+          !aNames.contains( aRule.Object2->GetName() ) ) {
+      anIter.remove();
+    }
+  }
+
+  endResetModel();
+}
+
+/**
+ Create new rule.
+ @return true if a rule has been created successfully
+ */
+bool HYDROGUI_PriorityTableModel::createNewRule() 
+{
+  if ( !canCreateNewRule() ) {
+    return false;
+  }
+  
+  // Existing pairs of object indexes
+  QStringList aNames = getAvailableObjectNames();
+  QList< QPair<int, int> > aRules;
+  foreach( const HYDROData_CustomRule& aRule, getRules() ) {
+    int anIndex1 = aNames.indexOf( aRule.Object1->GetName() );
+    int anIndex2 = aNames.indexOf( aRule.Object2->GetName() );
+    if ( anIndex1 >= 0 && anIndex2 >= 0 ) {
+      aRules << QPair<int, int>( anIndex1, anIndex2 );
+      aRules << QPair<int, int>( anIndex2, anIndex1 );
+    }
+  }
+    
+  // Try to find:
+  // 1. the new pair of objects 
+  // 2. the priority type corresponding to the objects order
+  Handle(HYDROData_Object) anObject1, anObject2;
+  HYDROData_PriorityType aPriorityType = GREATER;
+
+  int aNbObjects = myObjects.count();
+  for ( int anIndex1 = 0; anIndex1 < aNbObjects; anIndex1++ ) {
+    bool isFound = false;
+
+    for ( int anIndex2 = 0; anIndex2 < aNbObjects; anIndex2++ ) {
+      if ( anIndex1 == anIndex2 ) {
+        continue;
+      }
+
+      if ( !aRules.contains( QPair<int, int>( anIndex1, anIndex2 ) ) ) {
+        anObject1 = myObjects.at( anIndex1 );
+        anObject2 = myObjects.at( anIndex2 );
+        if ( anIndex1 > anIndex2 ) {
+          aPriorityType = LESS;
+        }
+        isFound = true;
+        break;
+      }
+    }
+
+    if ( isFound ) {
+      break;
+    }
+  }
+
+  // Create a new rule
+  bool isCreated = false;
+
+  if ( !anObject1.IsNull() && !anObject2.IsNull() ) {
+    HYDROData_CustomRule aNewRule;
+    aNewRule.Object1 = anObject1;
+    aNewRule.Object2 = anObject2;
+    aNewRule.Priority = aPriorityType;
+    aNewRule.MergeType = HYDROData_Zone::Merge_ZMIN;
+
+    beginResetModel();
+    myRules << aNewRule;
+    endResetModel();
+
+    isCreated = true;
+  }
+
+  return isCreated;
+}
+
+/**
+ Check if a new rule can be created.
+ @return true if a new rule could be created
+ */
+bool HYDROGUI_PriorityTableModel::canCreateNewRule() const
+{
+  int aNbObjects = myObjects.count();
+
+  return ( myRules.count() < (aNbObjects - 1)*aNbObjects/2 );
+}
+
+/**
+ */
+bool HYDROGUI_PriorityTableModel::removeRows ( int theRow, int theCount, const QModelIndex & theParent )
+{
+  if ( myRules.isEmpty() || theRow < 0 || theRow >= myRules.count() ) {
+    return false;
+  }
+
+  int aLastRow = theRow + theCount - 1;
+  if ( aLastRow > myRules.count() ) {
+    aLastRow = myRules.count() - 1;
+  }
+
+  beginRemoveRows( theParent, theRow, aLastRow );
+
+  // Remove the corresponding rules
+  for ( int i = 1; i <= theCount; i++ ) {
+    myRules.removeAt( theRow );
+  }
+
+  endRemoveRows();
+
+  return true;
+}
+
+/**
+ Remove all data from the model.
+ @return true if at least one row is removed
+ */
+bool HYDROGUI_PriorityTableModel::removeAll()
+{
+  return removeRows( 0, rowCount() );
+}
+
+/**
+ Get available pairs for the given object.
+ @param theObject the object
+ @return the list of object names
+ */
+QStringList HYDROGUI_PriorityTableModel::getAvailablePairs(  const Handle(HYDROData_Object)& theObject ) const
+{
+  QStringList aNames;
+
+  if ( !theObject.IsNull() ) {
+    aNames = getAvailableObjectNames();
+    aNames.removeAll( theObject->GetName() );
+  }
+
+  return aNames;
+}
+
+/**
+ Remove the rows.
+ @params theRows the list of rows to remove
+ @return true if at least one row is removed
+ */
+bool HYDROGUI_PriorityTableModel::removeRows ( const QList<int> theRows )
+{
+  QList<int> aSortedRows = theRows;
+  qSort( aSortedRows );
+
+  int aRowToRemove = -1;
+  int aNbRemoved = 0;
+  foreach ( int aRow, aSortedRows ) {
+    aRowToRemove = aRow - aNbRemoved;
+    if ( removeRow( aRowToRemove ) ) {
+      aNbRemoved++;
+    }
+  }
+
+  return ( aNbRemoved > 0 );
+}
+
+/**
+ Get priority string representation.
+ @param thePriority the priority
+ */
+QString HYDROGUI_PriorityTableModel::priorityToString( const int thePriority ) const
+{
+  switch( thePriority )
+  {
+  case LESS:
+    return tr( "LESS" );
+  case GREATER:
+    return tr( "GREATER" );
+  default:
+    return QString();
+  };
+}
+
+/**
+ Get merge type string representation.
+ @param theMergeType the merge type
+ */
+QString HYDROGUI_PriorityTableModel::mergeTypeToString( const int theMergeType ) const
+{
+  switch( theMergeType )
+  {
+  case HYDROData_Zone::Merge_Object:
+    return tr( "PRIORITY" );
+  case HYDROData_Zone::Merge_ZMIN:
+    return tr( "ZMIN" );
+  case HYDROData_Zone::Merge_ZMAX:
+    return tr( "ZMAX" );
+  default:
+    return QString();
+  };
+}
+
+/**
+  Check if the given pair of objects is already used.
+  @return true if the pair is used
+ */
+bool HYDROGUI_PriorityTableModel::isUsed( const Handle(HYDROData_Object)& theObj1, 
+                                          const Handle(HYDROData_Object)& theObj2 ) const
+{
+  bool isUsed = false;
+
+  foreach ( const HYDROData_CustomRule& aRule, myRules ) {
+    if ( ( aRule.Object1->GetName() == theObj1->GetName() && 
+           aRule.Object2->GetName() == theObj2->GetName() ) ||
+         ( aRule.Object1->GetName() == theObj2->GetName() && 
+           aRule.Object2->GetName() == theObj1->GetName() ) ) {
+      isUsed = true;
+      break;
+    }
+  }       
+
+  return isUsed;
+}
+
+/**
+  Get available object names.
+  @return the list of object names
+ */
+QStringList HYDROGUI_PriorityTableModel::getAvailableObjectNames() const
+{
+  QStringList aNames;
+
+  foreach ( const Handle(HYDROData_Object) anObj, myObjects ) {
+    if ( !anObj.IsNull() ) {
+      aNames << anObj->GetName();
+    }
+  }
+
+  return aNames;
+}
\ No newline at end of file
diff --git a/src/HYDROGUI/HYDROGUI_PriorityTableModel.h b/src/HYDROGUI/HYDROGUI_PriorityTableModel.h
new file mode 100644 (file)
index 0000000..f69190c
--- /dev/null
@@ -0,0 +1,95 @@
+// Copyright (C) 2007-2013  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
+//
+// 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.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_PriorityTableModel_H
+#define HYDROGUI_PriorityTableModel_H
+
+#include <HYDROGUI.h>
+#include <HYDROData_PriorityQueue.h>
+
+#include <QAbstractTableModel>
+#include <QStringList>
+
+
+class HYDROGUI_Module;
+
+
+/** 
+ * \class HYDROGUI_PriorityTableModel
+ * \brief The class representing custom table model for the priority rules
+ */
+class HYDRO_EXPORT HYDROGUI_PriorityTableModel : public QAbstractTableModel
+{
+  Q_OBJECT
+
+public:
+  HYDROGUI_PriorityTableModel( QObject* theParent = 0 );
+  virtual ~HYDROGUI_PriorityTableModel();
+
+  virtual Qt::ItemFlags        flags( const QModelIndex & theIndex ) const;
+
+  virtual QVariant data( const QModelIndex &theIndex, int theRole = Qt::DisplayRole ) const;  
+  virtual bool setData( const QModelIndex & theIndex, const QVariant & theValue, int theRole = Qt::EditRole );
+
+  virtual int rowCount( const QModelIndex &theParent = QModelIndex() ) const;
+  virtual int columnCount( const QModelIndex &theParent = QModelIndex() ) const;
+
+  virtual QVariant headerData( int theSection,
+                               Qt::Orientation theOrientation,
+                               int theRole = Qt::DisplayRole ) const;
+
+  virtual bool removeRows( int theRow, int theCount, const QModelIndex & theParent = QModelIndex() );
+  
+  bool removeRows( const QList<int> theRows );
+  bool removeAll();
+
+  void setObjects( const QList<Handle(HYDROData_Object)>& theObjects );
+
+  void setRules( const HYDROData_ListOfRules& theObjects );
+  HYDROData_ListOfRules getRules() const;
+
+  bool createNewRule();
+  bool canCreateNewRule() const;
+  
+protected:
+  bool isUsed( const Handle(HYDROData_Object)& theObj1, 
+               const Handle(HYDROData_Object)& theObj2 ) const;
+
+  QStringList getAvailablePairs( const Handle(HYDROData_Object)& theObject ) const;
+  QStringList getAvailableObjectNames() const;
+
+  QString priorityToString( const int thePriority ) const;
+  QString mergeTypeToString( const int theMergeType ) const;
+
+signals:
+  void showError( const QString& theMsg );
+
+private:
+  friend class test_HYDROGUI_PriorityTableModel;
+
+  HYDROGUI_Module* myModule;
+
+  HYDROData_ListOfRules myRules;
+  QList<Handle(HYDROData_Object)> myObjects;
+};
+
+#endif
\ No newline at end of file
diff --git a/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx b/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx
new file mode 100644 (file)
index 0000000..1545f66
--- /dev/null
@@ -0,0 +1,323 @@
+// Copyright (C) 2007-2013  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
+//
+// 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.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_PriorityWidget.h"
+
+#include "HYDROGUI_PriorityTableModel.h"
+
+#include "HYDROData_PriorityQueue.h"
+
+#include <SUIT_MessageBox.h>
+
+#include <QComboBox>
+#include <QHeaderView>
+#include <QLayout>
+#include <QTableView>
+#include <QToolButton>
+
+
+/**
+  Constructor.
+  @param theParent the parent object
+ */
+HYDROGUI_PriorityWidget::Delegate::Delegate( QObject* theParent )
+ : QStyledItemDelegate( theParent )
+{
+}
+
+/**
+ */
+QWidget* HYDROGUI_PriorityWidget::Delegate::createEditor( 
+  QWidget* theParent, const QStyleOptionViewItem& theOption,
+  const QModelIndex& theIndex ) const
+{
+  QComboBox* aComboBox = new QComboBox( theParent );
+
+  if ( theIndex.column() == 1 || theIndex.column() == 3 ) {
+    QMap<QString, QVariant> aMap = theIndex.data( Qt::UserRole ).toMap();
+    foreach ( QString aText, aMap.keys() ) {
+      aComboBox->addItem( aText, aMap.value( aText ).toInt() );
+    }
+  } else if ( theIndex.column() == 0 || theIndex.column() ==  2 ) {
+    QStringList anObjNames = theIndex.data( Qt::UserRole ).toStringList();
+    aComboBox->addItems( anObjNames );
+  }
+  
+  connect( aComboBox, SIGNAL( activated( int ) ), this, SLOT( finishEditing() ) );
+
+  return aComboBox;
+}
+
+/**
+ */
+void HYDROGUI_PriorityWidget::Delegate::setEditorData( 
+  QWidget* theEditor, const QModelIndex& theIndex ) const
+{
+  QComboBox* aComboBox = dynamic_cast<QComboBox*>( theEditor );
+
+  if ( aComboBox ) {
+    int anIndex = -1;
+
+    if ( theIndex.column() == 0 || theIndex.column() == 2 ) {
+      QString aText = theIndex.data( Qt::EditRole ).toString();
+      anIndex = aComboBox->findText( aText );
+    } else {
+      QVariant aData = theIndex.data( Qt::EditRole ).toInt();
+      anIndex = aComboBox->findData( aData );
+    }
+
+    if ( anIndex >= 0 ) {
+      aComboBox->setCurrentIndex( anIndex );
+    }
+  }
+}
+
+/**
+ */
+void HYDROGUI_PriorityWidget::Delegate::setModelData( 
+  QWidget* theEditor, QAbstractItemModel* theModel, const QModelIndex& theIndex) const
+{
+  QComboBox* aComboBox = dynamic_cast<QComboBox*>( theEditor );
+
+  if ( aComboBox ) {
+    int aColumn = theIndex.column();
+    if ( aColumn == 0 || aColumn == 2 ) {
+      QString aCurrentText = theIndex.data( Qt::EditRole ).toString();
+      QString aNewText = aComboBox->currentText();
+      if ( aNewText != aCurrentText ) {
+        theModel->setData( theIndex, aNewText );
+      }
+    } else {
+      theModel->setData( theIndex, aComboBox->itemData( aComboBox->currentIndex() ) );
+    }
+  }
+}
+
+/**
+ Emit signal indicating that the user has finished editing.
+ */
+void HYDROGUI_PriorityWidget::Delegate::finishEditing()
+{
+  QWidget* anEditor = qobject_cast<QWidget*>( sender() );
+  if ( anEditor ) {
+    emit commitData( anEditor );
+    emit closeEditor( anEditor );
+  }
+}
+
+
+/**
+  Constructor.
+  @param theParent the parent widget
+ */
+HYDROGUI_PriorityWidget::HYDROGUI_PriorityWidget( QWidget* theParent )
+: QWidget( theParent )
+{
+  // Main layout
+  QVBoxLayout* aMainLayout = new QVBoxLayout( this );
+  aMainLayout->setMargin( 0 );
+  aMainLayout->setSpacing( 5 );
+
+  // Buttons
+  myAdd = new QToolButton;
+  myAdd->setText( tr( "ADD" ) );
+  myRemove = new QToolButton;
+  myRemove->setText( tr( "REMOVE" ) );
+  myClear = new QToolButton;
+  myClear->setText( tr( "CLEAR_ALL" ) );
+  
+  // Table view
+  myTable = new QTableView( this );
+  myTable->setItemDelegate( new Delegate( this ) );
+  myTable->setEditTriggers( QAbstractItemView::DoubleClicked |
+                            QAbstractItemView::SelectedClicked |
+                            QAbstractItemView::EditKeyPressed );
+  
+  // Set the custom model
+  HYDROGUI_PriorityTableModel* aModel = new HYDROGUI_PriorityTableModel();
+  myTable->setModel( aModel );
+
+  // Set resize mode
+  myTable->horizontalHeader()->setStretchLastSection( false);
+  myTable->horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch );
+  myTable->horizontalHeader()->setResizeMode( 1, QHeaderView::ResizeToContents );
+  myTable->horizontalHeader()->setResizeMode( 2, QHeaderView::Stretch );
+  myTable->horizontalHeader()->setResizeMode( 3, QHeaderView::ResizeToContents );
+
+  myTable->verticalHeader()->setResizeMode( QHeaderView::ResizeToContents );
+  // Layout
+  // buttons
+  QHBoxLayout* aButtonsLayout = new QHBoxLayout();
+  aButtonsLayout->addWidget( myAdd );
+  aButtonsLayout->addWidget( myRemove );
+  aButtonsLayout->addStretch( 1 );
+  aButtonsLayout->addWidget( myClear );
+
+  // main
+  aMainLayout->addLayout( aButtonsLayout );
+  aMainLayout->addWidget( myTable );
+  
+  // Update controls
+  updateControls();
+
+  // Connections
+  connect( myAdd, SIGNAL( clicked() ), this, SLOT( onAddRule() ) );
+  connect( myRemove, SIGNAL( clicked() ), this, SLOT( onRemoveRule() ) );
+  connect( myClear, SIGNAL( clicked() ), this, SLOT( onClearRules() ) );
+
+  connect ( myTable->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), 
+            this, SLOT( onSelectionChanged() ) );
+
+  connect( aModel, SIGNAL( showError( const QString& ) ), this, SLOT( onShowError( const QString& ) ) );
+}
+
+/**
+  Destructor.
+ */
+HYDROGUI_PriorityWidget::~HYDROGUI_PriorityWidget()
+{
+}
+
+/**
+  Add the new default constructed rule.
+ */
+void HYDROGUI_PriorityWidget::onAddRule()
+{
+  HYDROGUI_PriorityTableModel* aModel = 
+    dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+  if ( aModel ) {
+    if (aModel->createNewRule()) {
+      updateControls();
+    }
+  }
+}
+
+/**
+  Remove the selected rule.
+ */
+void HYDROGUI_PriorityWidget::onRemoveRule()
+{
+  HYDROGUI_PriorityTableModel* aModel = 
+    dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+
+  if (aModel) {
+    QList<int> aRows;
+
+    QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedRows();
+    foreach ( const QModelIndex& anIndex, aSelectedIndexes ) {
+      aRows << anIndex.row();
+    }
+    
+    if ( aModel->removeRows( aRows ) ) {
+      updateControls();
+    }
+  }
+}
+
+/**
+  Clear all rules.
+ */
+void HYDROGUI_PriorityWidget::onClearRules()
+{
+  HYDROGUI_PriorityTableModel* aModel = 
+    dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+  if ( aModel && aModel->removeAll() ) {
+    updateControls();
+  }
+}
+
+/**
+  Set objects which could be used for rules definition.
+  @param theObjects the ordered list of objects
+ */
+void HYDROGUI_PriorityWidget::setObjects( const QList<Handle(HYDROData_Object)>& theObjects )
+{
+  HYDROGUI_PriorityTableModel* aModel = 
+    dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+  if( aModel ) {
+    aModel->setObjects( theObjects );
+    updateControls();
+  }
+}
+
+/**
+  Get rules.
+  @return the list of rules
+ */
+HYDROData_ListOfRules HYDROGUI_PriorityWidget::getRules() const
+{
+  HYDROData_ListOfRules aRules;
+
+  HYDROGUI_PriorityTableModel* aModel = 
+    dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+  if( aModel ) {
+    aRules = aModel->getRules();
+  }
+
+  return aRules;
+}
+
+/**
+  Set rules.
+  @param theRules the list of rules
+*/
+void HYDROGUI_PriorityWidget::setRules( const HYDROData_ListOfRules& theRules )
+{
+  HYDROGUI_PriorityTableModel* aModel = 
+    dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+  if( aModel ) {
+    aModel->setRules( theRules );
+    updateControls();
+  }
+}
+
+/**
+ Slot called on table selection change.
+*/
+void HYDROGUI_PriorityWidget::onSelectionChanged()
+{
+  QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedRows();
+  myRemove->setEnabled( aSelectedIndexes.count() > 0 );
+}
+
+/**
+ Update GUI controls state.
+ */
+void HYDROGUI_PriorityWidget::updateControls()
+{
+  HYDROGUI_PriorityTableModel* aModel = 
+    dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+  if( aModel ) {
+    myAdd->setEnabled( aModel->canCreateNewRule() );
+    bool isTableNotEmpty = aModel->rowCount() > 0;
+    myClear->setEnabled( isTableNotEmpty );
+  }
+  onSelectionChanged();
+}
+
+/**
+ Show error message.
+ */
+void HYDROGUI_PriorityWidget::onShowError( const QString& theMsg ) {
+  SUIT_MessageBox::warning( this, tr( "INCORRECT_INPUT" ), theMsg );
+}
\ No newline at end of file
diff --git a/src/HYDROGUI/HYDROGUI_PriorityWidget.h b/src/HYDROGUI/HYDROGUI_PriorityWidget.h
new file mode 100644 (file)
index 0000000..4162327
--- /dev/null
@@ -0,0 +1,99 @@
+// Copyright (C) 2007-2013  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
+//
+// 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.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_PRIORITYWIDGET_H
+#define HYDROGUI_PRIORITYWIDGET_H
+
+#include <HYDROGUI.h>
+
+#include <HYDROData_Object.h>
+#include <HYDROData_PriorityQueue.h>
+
+#include <QStyledItemDelegate>
+#include <QWidget>
+
+class QTableView;
+class QToolButton;
+
+/** 
+ * \class HYDROGUI_PriorityWidget
+ * \brief The class representing widget for tuning of the objects priorities and bathymetry conflicts
+ *
+ * The widget represents a table and a set of buttons (add and remove)
+ * providing the possibility to define priority rules.
+ */
+class HYDRO_EXPORT HYDROGUI_PriorityWidget : public QWidget
+{
+  Q_OBJECT
+
+  class Delegate;
+
+public:
+  HYDROGUI_PriorityWidget( QWidget* theParent );
+  virtual ~HYDROGUI_PriorityWidget();
+
+  void setObjects( const QList<Handle(HYDROData_Object)>& theObjects );
+
+  HYDROData_ListOfRules getRules() const;
+  void setRules( const HYDROData_ListOfRules& theRules );
+
+protected:
+  void updateControls();
+
+protected slots:
+  void onAddRule();
+  void onRemoveRule();
+  void onClearRules();
+
+  void onSelectionChanged();
+
+  void onShowError( const QString& theMsg );
+
+private:
+  QTableView*  myTable;  ///< the table view
+  QToolButton* myAdd;    ///< the add rule button
+  QToolButton* myRemove; ///< the remove rule button
+  QToolButton* myClear;  ///< the clear all rules button
+};
+
+/** 
+ * \class HYDROGUI_PriorityWidget::Delegate
+ * \brief The class representing custom item delegate (combobox)
+ */
+class HYDROGUI_PriorityWidget::Delegate : public QStyledItemDelegate
+{
+  Q_OBJECT
+
+public:
+  Delegate( QObject* theParent = 0 );
+  
+  QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
+                         const QModelIndex& ) const;
+  
+  void setEditorData( QWidget*, const QModelIndex& ) const;
+  void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
+
+protected slots:
+  void finishEditing();
+};
+
+#endif
index 35707867c75380e4f0d562cda2427f3f40e26a4d..d9f4a37dde1dcf0e67328149ffc9ec589255e967 100644 (file)
@@ -130,6 +130,17 @@ void HYDROGUI_Wizard::onBack()
   emit Back( aCurIdx );
 }
 
+void HYDROGUI_Wizard::onFirstPage()
+{
+  if ( myWizard->count() > 1 ) {
+    myNext->setVisible( true );
+    myFinish->setVisible( false );
+    myWizard->setCurrentIndex( 0 );
+    myBack->setEnabled( false );
+    emit Back( myWizard->currentIndex() );
+  }
+}
+
 bool HYDROGUI_Wizard::acceptCurrent() const
 {
   return true;
index 2d31434ab1225f63887e4c1134c337ae3d2b64d4..6699e8de64739bf3c925569bee3df1df4b93ace0 100644 (file)
@@ -47,6 +47,8 @@ public:
 public slots:
   void             onNext();
   void             onBack();
+  
+  void             onFirstPage();
 
 signals:
   void             Next( const int );
index 02b897a14c66dcfa53315985a23f34822cf0d57c..e74f56c4ff009f75e20bf93e4b90ba2f60a55f1d 100644 (file)
@@ -281,6 +281,22 @@ All supported formats (*.brep *.iges *.igs *.step *.stp)</translation>
       <source>EMPTY_GEOMETRY_OBJECTS</source>
       <translation>No one geometry object is selected, should be at least one.</translation>
     </message>
+    <message>
+      <source>MODE</source>
+      <translation>Mode</translation>
+    </message>
+    <message>
+      <source>AUTO</source>
+      <translation>Auto</translation>
+    </message>
+    <message>
+      <source>MANUAL</source>
+      <translation>Manual</translation>
+    </message>
+    <message>
+      <source>PRIORITY</source>
+      <translation>Priority</translation>
+    </message>
   </context>
 
   <context>
@@ -302,9 +318,25 @@ All supported formats (*.brep *.iges *.igs *.step *.stp)</translation>
       <translation>Regions list modification</translation>
     </message>
     <message>
-      <source>CONFIRM_SPLITTING_ZONES_RECALCULATION</source>
+      <source>CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS</source>
       <translation>Case splitting zones already exist and will be recalculated after regions list modification. Do you confirm the recalculation?</translation>
     </message>
+    <message>
+      <source>MODE_CHANGED</source>
+      <translation>Change creation mode</translation>
+    </message>
+    <message>
+      <source>CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE</source>
+      <translation>Case splitting zones already exist and will be recalculated after mode change. Do you confirm the recalculation?</translation>
+    </message>
+    <message>
+      <source>EMPTY_REGIONS</source>
+      <translation>Empty regions</translation>
+    </message>
+    <message>
+      <source>CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION</source>
+      <translation>Region(s): %1 do not contain any objects. Do you want to continue?</translation>
+    </message>
   </context>
 
   <context>
@@ -2137,4 +2169,64 @@ Polyline should consist from one not closed curve.</translation>
     </message>
   </context>
 
+  <context>
+    <name>HYDROGUI_PriorityWidget</name>
+    <message>
+      <source>ADD</source>
+      <translation>Add</translation>
+    </message>
+    <message>
+      <source>REMOVE</source>
+      <translation>Remove</translation>
+    </message>
+    <message>
+      <source>CLEAR_ALL</source>
+      <translation>Clear all</translation>
+    </message>
+    <message>
+      <source>INCORRECT_INPUT</source>
+      <translation>Incorrect input</translation>
+    </message>
+  </context>
+  
+  <context>
+    <name>HYDROGUI_PriorityTableModel</name>
+    <message>
+      <source>LESS</source>
+      <translation>&lt;</translation>
+    </message>
+    <message>
+      <source>GREATER</source>
+      <translation>&gt;</translation>
+    </message>
+    <message>
+      <source>PRIORITY</source>
+      <translation>Priority</translation>
+    </message>
+    <message>
+      <source>ZMIN</source>
+      <translation>Zmin</translation>
+    </message>
+    <message>
+      <source>ZMAX</source>
+      <translation>Zmax</translation>
+    </message>
+    <message>
+      <source>OBJECT1</source>
+      <translation>Object 1</translation>
+    </message>
+    <message>
+      <source>OBJECT2</source>
+      <translation>Object 2</translation>
+    </message>
+    <message>
+      <source>BATHYMETRY</source>
+      <translation>Bathymetry</translation>
+    </message>
+    <message>
+      <source>ALREADY_EXISTS</source>
+      <translation>The selected objects combination already exists.</translation>
+    </message>
+  </context>
+
 </TS>
index 48a257f9c9a568a55d9a52c999fb98d4a72d4d75..6bcfe0d244d1619abc0de70860e02217b9d7402f 100644 (file)
 
 %ExportedHeaderCode
 #include <HYDROData_CalculationCase.h>
+#include <HYDROData_PriorityQueue.h>
 %End
 
+enum HYDROData_PriorityType
+{
+  LESS,
+  GREATER,
+};
+
 class HYDROData_CalculationCase : public HYDROData_Entity
 {
 
@@ -53,6 +60,12 @@ public:
     POINT_ON    ///< point is on the edge of zone face
   };
 
+  enum AssignmentMode
+  {
+    MANUAL = 0,
+    AUTOMATIC,
+  };
+
 public:      
   /**
    * Add new one reference geometry object for calculation case.
@@ -280,6 +293,8 @@ public:
    */
 //TODO:  virtual bool Export( GEOM::GEOM_Gen_var theGeomEngine,
 //                       SALOMEDS::Study_ptr theStudy );
+       
+       QString Export( int theStudyId ) const;
 
 public:      
   // Public methods to work with Calculation services
@@ -472,6 +487,31 @@ public:
     Py_END_ALLOW_THREADS
   %End
 
+
+  void ClearRules();
+
+  void AddRule( HYDROData_Object                   theObject1,
+                HYDROData_PriorityType             thePriority,
+                HYDROData_Object                   theObject2,
+                HYDROData_Zone::MergeAltitudesType theMergeType )
+  [void ( const Handle_HYDROData_Object&, HYDROData_PriorityType, const Handle_HYDROData_Object&, HYDROData_Zone::MergeAltitudesType )];
+  %MethodCode
+    Handle(HYDROData_Object) anObject1 =
+      Handle(HYDROData_Object)::DownCast( createHandle( a0 ) );
+    Handle(HYDROData_Object) anObject2 =
+      Handle(HYDROData_Object)::DownCast( createHandle( a2 ) );
+
+    Py_BEGIN_ALLOW_THREADS
+    sipSelfWasArg ? sipCpp->HYDROData_CalculationCase::AddRule( anObject1, a1, anObject2, a3 ) : 
+                    sipCpp->AddRule( anObject1, a1, anObject2, a3 );
+    Py_END_ALLOW_THREADS
+  %End
+
+  QString DumpRules();
+
+  void SetAssignmentMode( AssignmentMode theMode );
+  AssignmentMode GetAssignmentMode() const;
+
 protected:
 
   /**