X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FStdMeshersGUI%2FStdMeshersGUI_SubShapeSelectorWdg.cxx;h=7986354934dbabdeb02b0353834f5990c5b8b989;hb=929ba51821ae4494080b840a7c30e2db0f078f5d;hp=8c2240803cd2f493ca37e0d90c9524a86efa4bd6;hpb=bd4e115a78b52e3fbc016e5e30bb0e19b2a9e7d6;p=modules%2Fsmesh.git diff --git a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx index 8c2240803..798635493 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE // // 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. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -43,7 +43,6 @@ // SALOME GUI includes #include #include -#include // SUIT Includes #include @@ -68,9 +67,6 @@ #include #include -// SALOME KERNEL includes -#include - #define SPACING 6 #define MARGIN 0 @@ -249,9 +245,9 @@ void StdMeshersGUI_SubShapeSelectorWdg::SelectionIntoArgument() for ( ; anIt.More(); anIt.Next()) { // Loop on selected objects Handle(SALOME_InteractiveObject) IO = anIt.Value(); - GEOM::GEOM_Object_var aGeomObj = GetGeomObjectByEntry( IO->getEntry() ); + GEOM::GEOM_Object_var aGeomObj = GetGeomObjectByEntry( IO->getEntry() ); if ( !CORBA::is_nil( aGeomObj ) ) { // Selected Object From Study - GEOM::GEOM_Object_ptr aGeomFatherObj = aGeomObj->GetMainShape(); + GEOM::GEOM_Object_var aGeomFatherObj = aGeomObj->GetMainShape(); QString aFatherEntry = ""; QString aMainFatherEntry = ""; TopoDS_Shape shape; @@ -259,13 +255,13 @@ void StdMeshersGUI_SubShapeSelectorWdg::SelectionIntoArgument() // Get Main Shape GEOM::GEOM_Object_var aGeomMain = GetGeomObjectByEntry( myEntry ); if ( !CORBA::is_nil( aGeomMain ) && aGeomMain->GetType() == 37 ) { // Main Shape is a Group - GEOM::GEOM_Object_ptr aMainFatherObj = aGeomMain->GetMainShape(); + GEOM::GEOM_Object_var aMainFatherObj = aGeomMain->GetMainShape(); if ( !CORBA::is_nil( aMainFatherObj ) ) aMainFatherEntry = aMainFatherObj->GetStudyEntry(); } aFatherEntry = aGeomFatherObj->GetStudyEntry(); } - + if ( aFatherEntry != "" && ( aFatherEntry == myEntry || aFatherEntry == aMainFatherEntry ) ) { if ( aGeomObj->GetType() == 37 /*GEOM_GROUP*/ ) { // Selected Group that belongs the main object @@ -303,7 +299,9 @@ void StdMeshersGUI_SubShapeSelectorWdg::SelectionIntoArgument() } } // update add button - myAddButton->setEnabled( ( myListWidget->count() < myMaxSize || myMaxSize == -1 ) && mySelectedIDs.size() > 0 && ( mySelectedIDs.size() <= myMaxSize || myMaxSize == -1 ) ); + myAddButton->setEnabled( ( myListWidget->count() < myMaxSize || myMaxSize == -1 ) && + mySelectedIDs.size() > 0 && + ( mySelectedIDs.size() <= myMaxSize || myMaxSize == -1 ) ); //Connect Selected Ids in viewer and dialog's Ids list bool signalsBlocked = myListWidget->blockSignals( true ); @@ -468,18 +466,17 @@ GEOM::GEOM_Object_var StdMeshersGUI_SubShapeSelectorWdg::GetGeomObjectByEntry( c { GEOM::GEOM_Object_var aGeomObj; SALOMEDS::Study_var aStudy = SMESHGUI::GetSMESHGen()->GetCurrentStudy(); - if (aStudy != 0) { + if ( !aStudy->_is_nil() ) + { SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( theEntry.toLatin1().data() ); - SALOMEDS::GenericAttribute_var anAttr; - - if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) { - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - CORBA::String_var aVal = anIOR->Value(); - CORBA::Object_var obj = aStudy->ConvertIORToObject(aVal); + if (!aSObj->_is_nil() ) + { + CORBA::Object_var obj = aSObj->GetObject(); aGeomObj = GEOM::GEOM_Object::_narrow(obj); + aSObj->UnRegister(); } } - return aGeomObj; + return aGeomObj._retn(); } //================================================================================= @@ -517,9 +514,9 @@ SMESH::long_array_var StdMeshersGUI_SubShapeSelectorWdg::GetListOfIDs() //================================================================================= // function : SetListOfIds -// purpose : Called to set the list of SubShapes IDs +// purpose : Called to set the list of SubShapes IDs. Returns false if any ID is invalid //================================================================================= -void StdMeshersGUI_SubShapeSelectorWdg::SetListOfIDs( SMESH::long_array_var theIds) +bool StdMeshersGUI_SubShapeSelectorWdg::SetListOfIDs( SMESH::long_array_var theIds) { mySelectedIDs.clear(); myListOfIDs.clear(); @@ -527,8 +524,10 @@ void StdMeshersGUI_SubShapeSelectorWdg::SetListOfIDs( SMESH::long_array_var theI for ( int i = 0; i < size; i++ ) mySelectedIDs.append( theIds[ i ] ); - mySelectedIDs = GetCorrectedListOfIDs( false ); + bool isOk; + mySelectedIDs = GetCorrectedListOfIDs( false, &isOk ); onAdd(); + return isOk; } //================================================================================= @@ -558,35 +557,74 @@ const char* StdMeshersGUI_SubShapeSelectorWdg::GetMainShapeEntry() // function : GetCorrectedListOfIds // purpose : Called to convert the list of IDs from sub-shape IDs to main shape IDs //================================================================================= -QList StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSubshapeToMainshape ) +QList +StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSubshapeToMainshape, + bool* isOK ) { - if ( ( myMainShape.IsNull() || myGeomShape.IsNull() ) && fromSubshapeToMainshape ) + if (( myMainShape.IsNull() || myGeomShape.IsNull() ) && fromSubshapeToMainshape ) return myListOfIDs; - else if ( ( myMainShape.IsNull() || myGeomShape.IsNull() ) && !fromSubshapeToMainshape ) + else if (( myMainShape.IsNull() /*||*/&& myGeomShape.IsNull() ) && !fromSubshapeToMainshape ) return mySelectedIDs; + if ( !fromSubshapeToMainshape ) // called from SetListOfIDs + { + if ( myMainShape.IsNull() ) + std::swap( myMainShape, myGeomShape ); + } + QList aList; - TopTools_IndexedMapOfShape aGeomMap; - TopTools_IndexedMapOfShape aMainMap; - TopExp::MapShapes(myGeomShape, aGeomMap); + TopTools_IndexedMapOfShape aGeomMap, aMainMap; TopExp::MapShapes(myMainShape, aMainMap); + if ( !myGeomShape.IsNull() ) + TopExp::MapShapes(myGeomShape, aGeomMap); - if ( fromSubshapeToMainshape ) { // convert indexes from sub-shape to mainshape + bool ok = true; + if ( fromSubshapeToMainshape ) // convert indexes from sub-shape to mainshape + { int size = myListOfIDs.size(); for (int i = 0; i < size; i++) { - TopoDS_Shape aSubShape = aGeomMap.FindKey( myListOfIDs.at(i) ); - int index = aMainMap.FindIndex( aSubShape ); + int index = myListOfIDs.at(i); + if ( aGeomMap.Extent() < index ) + { + ok = false; + } + else + { + TopoDS_Shape aSubShape = aGeomMap.FindKey( index ); + if ( mySubShType != aSubShape.ShapeType() ) + ok = false; + if ( !aMainMap.Contains( aSubShape )) + ok = false; + else + index = aMainMap.FindIndex( aSubShape ); + } aList.append( index ); } myIsNotCorrected = false; - } else { // convert indexes from main shape to sub-shape + } + else // convert indexes from main shape to sub-shape, or just check indices + { int size = mySelectedIDs.size(); for (int i = 0; i < size; i++) { - TopoDS_Shape aSubShape = aMainMap.FindKey( mySelectedIDs.at(i) ); - int index = aGeomMap.FindIndex( aSubShape ); + int index = mySelectedIDs.at(i); + if ( aMainMap.Extent() < index ) + { + ok = false; + } + else + { + TopoDS_Shape aSubShape = aMainMap.FindKey( index ); + if ( mySubShType != aSubShape.ShapeType() ) + ok = false; + if ( !aGeomMap.Contains( aSubShape ) && !aGeomMap.IsEmpty() ) + ok = false; + else + index = aGeomMap.FindIndex( aSubShape ); + } aList.append( index ); } } + if ( isOK ) *isOK = ok; return aList; }