Salome HOME
lost icon for dummy3d
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Tool2.cxx
index ef1962e806843c903ee22a05a0b1f0821fc2bd86..3dda8c6bd2ad89fceb4254dfae98dd670bd5b927 100644 (file)
@@ -54,7 +54,28 @@ int HYDROGUI_Tool::GetActiveStudyId()
   return 0;
 }
 
-
+static bool GetCalCaseSubT(const QString& aHydroPref, 
+  const QString& anEntry, 
+  const QString& SubTPostFix,
+  HYDROGUI_DataModel* aModel,
+  Handle(HYDROData_CalculationCase)& theOutCalCase)
+{
+  int aFiB = anEntry.lastIndexOf(SubTPostFix, -1, Qt::CaseInsensitive);
+  if (aFiB != -1)
+  {
+    QString RightTruncEntry = anEntry.left(anEntry.length() - SubTPostFix.length());
+    Handle(HYDROData_CalculationCase) CalCase = 
+      Handle(HYDROData_CalculationCase)::DownCast (aModel->objectByEntry( RightTruncEntry, KIND_CALCULATION ));
+    if (CalCase)
+    {
+      theOutCalCase = CalCase;
+      return true;
+    }
+    else
+      return false;
+  }
+  return false;
+}
 
 void HYDROGUI_Tool::SetActiveViewManager( HYDROGUI_Module* theModule,
                                           SUIT_ViewManager* theViewManager )
@@ -251,8 +272,71 @@ ObjectKind HYDROGUI_Tool::GetSelectedPartition( HYDROGUI_Module* theModule )
   return KIND_UNKNOWN;
 }
 
+bool HYDROGUI_Tool::IsSelectedPartOfCalcCase( HYDROGUI_Module* theModule, Handle(HYDROData_CalculationCase)& theOutCalCase,
+  QString& theOutPart)
+{
+  HYDROGUI_DataModel* aModel = theModule->getDataModel();
+  SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr();
+  SUIT_DataOwnerPtrList anOwners;
+  aSelectionMgr->selected( anOwners );
 
+  if( anOwners.size() != 1 )
+    return false;
+
+  LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( anOwners.first().operator->() );
 
+  if( anOwner )
+  {
+    QString anEntry = anOwner->entry();
+    QString aHydroPref = "_" + HYDROGUI_DataObject::entryPrefix();
+    //
+    QString aPostFixBoundary = aHydroPref + HYDROGUI_DataModel::tr("CASE_BOUNDARY");
+    if (GetCalCaseSubT(anEntry, anEntry, aPostFixBoundary, aModel, theOutCalCase ))
+    {
+      theOutPart = HYDROGUI_DataModel::tr("CASE_BOUNDARY");
+      theOutPart.toUpper();
+      return true;
+    }
+    //
+    QString aPostFixAO = aHydroPref + 
+      HYDROGUI_DataModel::tr( HYDROGUI_DataModel::partitionName( KIND_ARTIFICIAL_OBJECT ).toLatin1().constData());
+    if (GetCalCaseSubT(anEntry, anEntry, aPostFixAO, aModel, theOutCalCase ))
+    {
+      aPostFixAO.remove(0, aHydroPref.length());
+      theOutPart = aPostFixAO;
+      return true;
+    }
+    //
+    QString aPostFixNO = aHydroPref + 
+      HYDROGUI_DataModel::tr( HYDROGUI_DataModel::partitionName( KIND_NATURAL_OBJECT ).toLatin1().constData());
+    if (GetCalCaseSubT(anEntry, anEntry, aPostFixNO, aModel, theOutCalCase ))
+    {
+      aPostFixNO.remove(0, aHydroPref.length());
+      theOutPart = aPostFixNO;
+      return true;
+    }
+    //
+    QString aPostFixLCM = aHydroPref + 
+      HYDROGUI_DataModel::tr( HYDROGUI_DataModel::partitionName( KIND_LAND_COVER_MAP ).toLatin1().constData());
+    if (GetCalCaseSubT(anEntry, anEntry, aPostFixLCM, aModel, theOutCalCase ))
+    {
+      aPostFixLCM.remove(0, aHydroPref.length());
+      theOutPart = aPostFixLCM;
+      return true;
+    }
+    //
+    QString aPostFixReg = aHydroPref + 
+      HYDROGUI_DataModel::tr( HYDROGUI_DataModel::partitionName( KIND_REGION ).toLatin1().constData());
+    if (GetCalCaseSubT(anEntry, anEntry, aPostFixReg, aModel, theOutCalCase ))
+    {
+      aPostFixReg.remove(0, aHydroPref.length());
+      theOutPart = aPostFixReg;
+      return true;
+    }
+    //
+  }
+  return false;
+}
 
 QStringList HYDROGUI_Tool::GetSelectedGeomObjects( HYDROGUI_Module* theModule,
                                                    QList<GEOM::shape_type> theTypes )