From: Paul RASCLE Date: Wed, 7 Jan 2015 19:18:22 +0000 (+0000) Subject: merge BR_hydro_v_1_0_4 on BR_quadtree X-Git-Tag: BR_quadtree_20150925~25 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9d657ba909dc1123967fae5790115866b406197c;p=modules%2Fhydro.git merge BR_hydro_v_1_0_4 on BR_quadtree --- diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index 06b6ba09..53fb279f 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -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 diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index dcc662d6..e97ae06c 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -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 @@ -33,6 +31,7 @@ #include #include #include +#include //#define DEB_CALCULATION 1 #ifdef DEB_CALCULATION @@ -49,6 +48,9 @@ #define EXPORT_NAME "HYDRO_" + GetName() +#include +#include + #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 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 aRegionsMap; //object name to region + QMap 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::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 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 = "<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 ); +} diff --git a/src/HYDROData/HYDROData_CalculationCase.h b/src/HYDROData/HYDROData_CalculationCase.h index 3629a7dd..4f0ed90f 100644 --- a/src/HYDROData/HYDROData_CalculationCase.h +++ b/src/HYDROData/HYDROData_CalculationCase.h @@ -4,6 +4,10 @@ #define HYDROData_CalculationCase_HeaderFile #include +#include +#include +#include +#include // IDL includes #include @@ -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 diff --git a/src/HYDROData/HYDROData_Document.cxx b/src/HYDROData/HYDROData_Document.cxx index 5f95e02b..3568066a 100644 --- a/src/HYDROData/HYDROData_Document.cxx +++ b/src/HYDROData/HYDROData_Document.cxx @@ -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 ); diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index fc5fe6c2..ba2cb941 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -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() ); +} diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index d639c4a7..dcc6912b 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -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: /** diff --git a/src/HYDROData/HYDROData_Obstacle.cxx b/src/HYDROData/HYDROData_Obstacle.cxx index b7c8eb54..7d0469ca 100644 --- a/src/HYDROData/HYDROData_Obstacle.cxx +++ b/src/HYDROData/HYDROData_Obstacle.cxx @@ -41,6 +41,9 @@ #include +#include +#include + 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 ) diff --git a/src/HYDROData/HYDROData_Obstacle.h b/src/HYDROData/HYDROData_Obstacle.h index 3641ba9d..85373efd 100644 --- a/src/HYDROData/HYDROData_Obstacle.h +++ b/src/HYDROData/HYDROData_Obstacle.h @@ -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 index 00000000..075f70a0 --- /dev/null +++ b/src/HYDROData/HYDROData_PriorityQueue.cxx @@ -0,0 +1,275 @@ + +#include +#include +#include +#include +#include +#include + +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 index 00000000..62c8708d --- /dev/null +++ b/src/HYDROData/HYDROData_PriorityQueue.h @@ -0,0 +1,66 @@ + +#ifndef HYDROData_PriorityQueue_HeaderFile +#define HYDROData_PriorityQueue_HeaderFile + +#include +#include +#include + +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_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 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 + diff --git a/src/HYDROData/HYDROData_Region.cxx b/src/HYDROData/HYDROData_Region.cxx index ac6a4f75..45d7b9e7 100644 --- a/src/HYDROData/HYDROData_Region.cxx +++ b/src/HYDROData/HYDROData_Region.cxx @@ -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 #include @@ -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 diff --git a/src/HYDROData/HYDROData_Region.h b/src/HYDROData/HYDROData_Region.h index 3307b324..45fd385c 100644 --- a/src/HYDROData/HYDROData_Region.h +++ b/src/HYDROData/HYDROData_Region.h @@ -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: diff --git a/src/HYDROData/HYDROData_SplitToZonesTool.cxx b/src/HYDROData/HYDROData_SplitToZonesTool.cxx index fabf15d9..3df841ed 100644 --- a/src/HYDROData/HYDROData_SplitToZonesTool.cxx +++ b/src/HYDROData/HYDROData_SplitToZonesTool.cxx @@ -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() < #include #include -#include -#include +#include +#include #include #include @@ -54,11 +54,11 @@ public: typedef QList SplitDataList; typedef QListIterator SplitDataListIterator; - typedef NCollection_Map HYDROData_MapOfShape; + typedef NCollection_IndexedMap HYDROData_MapOfShape; typedef HYDROData_MapOfShape::Iterator HYDROData_MapIteratorOfMapOfShape; - typedef NCollection_DataMap HYDROData_DataMapOfShapeListOfShape; + typedef NCollection_IndexedDataMap HYDROData_DataMapOfShapeListOfShape; typedef HYDROData_DataMapOfShapeListOfShape::Iterator HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape; - typedef NCollection_DataMap HYDROData_DataMapOfShapeListOfString; + typedef NCollection_IndexedDataMap 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 index 00000000..b8ba7ae3 --- /dev/null +++ b/src/HYDROData/HYDROData_Warning.h @@ -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 diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index a3acda81..a1928801 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -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( diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index ba31ad82..9b2bfda7 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -26,11 +26,14 @@ #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 #include @@ -45,9 +48,12 @@ #include #include +#include #include #include +#include +#include #include #include #include @@ -55,10 +61,13 @@ #include #include #include +#include +#include +#include #include +#include #include -#include -#include + 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 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 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 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 HYDROGUI_CalculationDlg::getGeometryObjects() +{ + QList anEntities = myGeomObjects->getObjects(); + QList 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 diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index eaf3aa26..5010b7d2 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -27,16 +27,23 @@ #include 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 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; }; diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index f3b4351c..898a3c1e 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -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( 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( inputPanel() ); + if ( !aPanel ) + return; + + if ( !confirmModeChange() ) { + aPanel->setMode( myEditedObject->GetAssignmentMode() ); + return; + } + + myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode ); + aPanel->setMode( theMode ); +} diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.h b/src/HYDROGUI/HYDROGUI_CalculationOp.h index 81c19c61..271bb52d 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.h +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.h @@ -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; diff --git a/src/HYDROGUI/HYDROGUI_DataBrowser.cxx b/src/HYDROGUI/HYDROGUI_DataBrowser.cxx index d5460b64..86e069df 100644 --- a/src/HYDROGUI/HYDROGUI_DataBrowser.cxx +++ b/src/HYDROGUI/HYDROGUI_DataBrowser.cxx @@ -42,6 +42,7 @@ #include #include +#include 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() ) { + aView->setDragEnabled ( !theIsReadOnly ); + aView->setEditTriggers ( theIsReadOnly ? + QAbstractItemView::NoEditTriggers : + QAbstractItemView::DoubleClicked ); + } + + // Enable/disable rename shortcut + QList aShortcuts = findChildren(); + QShortcut* aShortcut; + foreach( aShortcut, aShortcuts ) { + if ( aShortcut->key() == QKeySequence( shortcutKey( RenameShortcut ) ) ) { + aShortcut->setEnabled( !theIsReadOnly ); + } + } +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_DataBrowser.h b/src/HYDROGUI/HYDROGUI_DataBrowser.h index 11856cf6..82620c5b 100644 --- a/src/HYDROGUI/HYDROGUI_DataBrowser.h +++ b/src/HYDROGUI/HYDROGUI_DataBrowser.h @@ -48,6 +48,8 @@ public: */ virtual SUIT_DataObject* findObject( const QString& ) const; + void setReadOnly( const bool theIsReadOnly ); + signals: void dropped( const QList& theList, SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction ); diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index 6f1adada..ee3b3fdd 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -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( + findObject( HYDROGUI_DataObject::dataObjectEntry( theModelObject ) ) ); + return aGuiObj; } HYDROGUI_DataObject* HYDROGUI_DataModel::getReferencedDataObject( HYDROGUI_DataObject* theObject ) diff --git a/src/HYDROGUI/HYDROGUI_DataObject.cxx b/src/HYDROGUI/HYDROGUI_DataObject.cxx index 9701970a..6f2b9cce 100644 --- a/src/HYDROGUI/HYDROGUI_DataObject.cxx +++ b/src/HYDROGUI/HYDROGUI_DataObject.cxx @@ -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, diff --git a/src/HYDROGUI/HYDROGUI_ExportCalculationOp.cxx b/src/HYDROGUI/HYDROGUI_ExportCalculationOp.cxx index d91522bb..f5128a9b 100644 --- a/src/HYDROGUI/HYDROGUI_ExportCalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ExportCalculationOp.cxx @@ -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; } diff --git a/src/HYDROGUI/HYDROGUI_ListModel.cxx b/src/HYDROGUI/HYDROGUI_ListModel.cxx index 24e3fe8f..e6deaf42 100644 --- a/src/HYDROGUI/HYDROGUI_ListModel.cxx +++ b/src/HYDROGUI/HYDROGUI_ListModel.cxx @@ -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& 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 diff --git a/src/HYDROGUI/HYDROGUI_ListModel.h b/src/HYDROGUI/HYDROGUI_ListModel.h index 12ca7f71..ea65f808 100644 --- a/src/HYDROGUI/HYDROGUI_ListModel.h +++ b/src/HYDROGUI/HYDROGUI_ListModel.h @@ -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& 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& theItems, const int theDropItem ) const; @@ -83,6 +88,8 @@ private: Object2VisibleList myObjects; QPixmap myEmpty, myEye; + + bool myIsDecorationEnabled; }; #endif \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 51e6c303..e46e0cd9 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -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() ); diff --git a/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx b/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx index 1308378f..8c23d224 100644 --- a/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx +++ b/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx @@ -37,12 +37,14 @@ /** 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 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( myList->model() ); + if ( aFilterModel ) { + HYDROGUI_ListModel* aSourceModel = + dynamic_cast( 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( myList->model() ); if( aFilterModel ) { HYDROGUI_ListModel* aModel = dynamic_cast( aFilterModel->sourceModel() ); @@ -239,10 +322,14 @@ void HYDROGUI_OrderedListWidget::onMove( int theType ) aSelectedSourceIndexes << aFilterModel->mapToSource( anIndex ); } QList 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 diff --git a/src/HYDROGUI/HYDROGUI_OrderedListWidget.h b/src/HYDROGUI/HYDROGUI_OrderedListWidget.h index e199fb7a..31faba84 100644 --- a/src/HYDROGUI/HYDROGUI_OrderedListWidget.h +++ b/src/HYDROGUI/HYDROGUI_OrderedListWidget.h @@ -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 index 00000000..6d737e3a --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PriorityTableModel.cxx @@ -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 aMap; + aMap.insert( priorityToString( LESS ), LESS ); + aMap.insert( priorityToString( GREATER ), GREATER ); + aVariant = QVariant( aMap ); + } else if ( aColumn == 3 ) { + QMap 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& theObjects ) +{ + myObjects = theObjects; + + beginResetModel(); + + // Remove rules which use objects which are no longer available + QStringList aNames = getAvailableObjectNames(); + QMutableListIterator 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 > 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( anIndex1, anIndex2 ); + aRules << QPair( 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( 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 theRows ) +{ + QList 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 index 00000000..f69190c1 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PriorityTableModel.h @@ -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 +#include + +#include +#include + + +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 theRows ); + bool removeAll(); + + void setObjects( const QList& 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 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 index 00000000..1545f667 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx @@ -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 + +#include +#include +#include +#include +#include + + +/** + 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 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( 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( 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( 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( myTable->model() ); + if ( aModel ) { + if (aModel->createNewRule()) { + updateControls(); + } + } +} + +/** + Remove the selected rule. + */ +void HYDROGUI_PriorityWidget::onRemoveRule() +{ + HYDROGUI_PriorityTableModel* aModel = + dynamic_cast( myTable->model() ); + + if (aModel) { + QList 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( 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& theObjects ) +{ + HYDROGUI_PriorityTableModel* aModel = + dynamic_cast( 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( 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( 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( 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 index 00000000..4162327c --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PriorityWidget.h @@ -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 + +#include +#include + +#include +#include + +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& 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 diff --git a/src/HYDROGUI/HYDROGUI_Wizard.cxx b/src/HYDROGUI/HYDROGUI_Wizard.cxx index 35707867..d9f4a37d 100644 --- a/src/HYDROGUI/HYDROGUI_Wizard.cxx +++ b/src/HYDROGUI/HYDROGUI_Wizard.cxx @@ -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; diff --git a/src/HYDROGUI/HYDROGUI_Wizard.h b/src/HYDROGUI/HYDROGUI_Wizard.h index 2d31434a..6699e8de 100644 --- a/src/HYDROGUI/HYDROGUI_Wizard.h +++ b/src/HYDROGUI/HYDROGUI_Wizard.h @@ -47,6 +47,8 @@ public: public slots: void onNext(); void onBack(); + + void onFirstPage(); signals: void Next( const int ); diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 02b897a1..e74f56c4 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -281,6 +281,22 @@ All supported formats (*.brep *.iges *.igs *.step *.stp) EMPTY_GEOMETRY_OBJECTS No one geometry object is selected, should be at least one. + + MODE + Mode + + + AUTO + Auto + + + MANUAL + Manual + + + PRIORITY + Priority + @@ -302,9 +318,25 @@ All supported formats (*.brep *.iges *.igs *.step *.stp) Regions list modification - CONFIRM_SPLITTING_ZONES_RECALCULATION + CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS Case splitting zones already exist and will be recalculated after regions list modification. Do you confirm the recalculation? + + MODE_CHANGED + Change creation mode + + + CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE + Case splitting zones already exist and will be recalculated after mode change. Do you confirm the recalculation? + + + EMPTY_REGIONS + Empty regions + + + CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION + Region(s): %1 do not contain any objects. Do you want to continue? + @@ -2137,4 +2169,64 @@ Polyline should consist from one not closed curve. + + HYDROGUI_PriorityWidget + + ADD + Add + + + REMOVE + Remove + + + CLEAR_ALL + Clear all + + + INCORRECT_INPUT + Incorrect input + + + + + HYDROGUI_PriorityTableModel + + LESS + < + + + GREATER + > + + + PRIORITY + Priority + + + ZMIN + Zmin + + + ZMAX + Zmax + + + OBJECT1 + Object 1 + + + OBJECT2 + Object 2 + + + BATHYMETRY + Bathymetry + + + ALREADY_EXISTS + The selected objects combination already exists. + + + diff --git a/src/HYDROPy/HYDROData_CalculationCase.sip b/src/HYDROPy/HYDROData_CalculationCase.sip index 48a257f9..6bcfe0d2 100644 --- a/src/HYDROPy/HYDROData_CalculationCase.sip +++ b/src/HYDROPy/HYDROData_CalculationCase.sip @@ -22,8 +22,15 @@ %ExportedHeaderCode #include +#include %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: /**