+
+bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
+ SALOMEDS::Study_ptr theStudy,
+ const NCollection_IndexedDataMap<TopoDS_Shape, QString>& aShToName,
+ const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
+ QString& theGeomObjEntry ) const
+{
+ // Sew faces
+ BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
+ aSewing.SetNonManifoldMode( Standard_False );
+#ifdef DEB_CALCULATION
+ TCollection_AsciiString aNam("Sh_");
+ int i=1;
+#endif
+ TopTools_DataMapOfShapeListOfShape SH2M;
+ for ( int i = 1; i <= aShToName.Extent(); i++ )
+ {
+ const TopoDS_Shape& aShape = aShToName.FindKey(i);
+ if ( aShape.IsNull() )
+ continue;
+
+ SH2M.Bind(aShape, TopTools_ListOfShape());
+ TopTools_ListOfShape& LM = SH2M.ChangeFind(aShape);
+ if ( aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL )
+ {
+ aSewing.Add( aShape );
+ LM.Append(aShape);
+ }
+ else if (aShape.ShapeType() == TopAbs_COMPOUND)
+ {
+ TopExp_Explorer anExp( aShape, TopAbs_SHELL );
+ for (; anExp.More(); anExp.Next() )
+ {
+ aSewing.Add( anExp.Current() );
+ LM.Append(anExp.Current());
+ }
+ anExp.Init( aShape, TopAbs_FACE, TopAbs_SHELL );
+ for (; anExp.More(); anExp.Next() )
+ {
+ aSewing.Add( anExp.Current() );
+ LM.Append(anExp.Current());
+ }
+ }
+ } // faces iterator
+
+ aSewing.Perform();
+ TopoDS_Shape aSewedShape = aSewing.SewedShape();
+
+ NCollection_IndexedDataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> aFacesToNameModif;
+
+ for ( int i = 1; i <= aShToName.Extent(); i++ )
+ {
+ const TopoDS_Shape& CurShape = aShToName.FindKey(i);
+ const QString& Qstr = aShToName.FindFromIndex(i);
+ const TopTools_ListOfShape& LM = SH2M(CurShape);
+ for (TopTools_ListIteratorOfListOfShape it(LM); it.More(); it.Next())
+ {
+ const TopoDS_Shape& csh = it.Value();
+ if (aSewing.IsModified(csh))
+ aFacesToNameModif.Add(aSewing.Modified(csh), Qstr);
+ else
+ aFacesToNameModif.Add(csh, Qstr);
+ }
+ }
+
+
+ // If the sewed shape is empty - return false
+ if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
+ return false;
+
+#ifdef DEB_CALCULATION
+ BRepTools::Write(aSewedShape ,"Sew.brep");
+#endif // Publish the sewed shape
+ QString aName = EXPORT_NAME;
+ GEOM::GEOM_Object_ptr aMainShape =
+ HYDROData_GeomTool::ExplodeShapeInGEOMandPublish( theGeomEngine, theStudy, aSewedShape, aFacesToNameModif, aName, theGeomObjEntry );
+
+ if ( aMainShape->_is_nil() )
+ return false;
+
+ if ( theGroupsDefs.IsEmpty() )
+ return true;
+
+ // Create groups
+ TopTools_IndexedMapOfShape aMapOfSubShapes;
+ TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
+
+ NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
+
+ for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
+ {
+ const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
+
+ NCollection_Sequence<int> aGroupIndexes;
+ for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
+ {
+ const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
+#ifdef DEB_CALCULATION
+ cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
+#endif
+
+ TopoDS_Shape aModifiedShape = aShape;
+ if ( aSewing.IsModified( aShape ) )
+ aModifiedShape = aSewing.Modified( aShape );
+ else if ( aSewing.IsModifiedSubShape( aShape ) )
+ aModifiedShape = aSewing.ModifiedSubShape( aShape );
+
+#ifdef DEB_CALCULATION
+ const TopLoc_Location& aL1 = aShape.Location();
+ const TopLoc_Location& aL2 = aModifiedShape.Location();
+ cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
+#endif
+
+ int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
+ if ( anIndex > 0 ) {
+ aGroupIndexes.Append( anIndex );
+ } else {
+#ifdef DEB_CALCULATION
+ TCollection_AsciiString aNam("Lost_");
+ if(!aMapOfSubShapes.Contains(aModifiedShape)) {
+ for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
+ {
+ const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
+ if ( aModifiedShape.IsPartner( aS ) )
+ {
+ cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
+ TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
+ BRepTools::Write(aS ,aName.ToCString());
+ break;
+ }
+ }
+ }
+#endif
+ }
+ }
+ if ( !aGroupIndexes.IsEmpty() )
+ aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
+ }
+
+ if ( !aGroupsData.IsEmpty() )
+ {
+ GEOM::GEOM_IGroupOperations_var aGroupOp =
+ theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
+
+ NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
+ for ( ; aMapIt.More(); aMapIt.Next() )
+ {
+ const TCollection_AsciiString& aGroupName = aMapIt.Key();
+ const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
+
+ GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
+ if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
+ continue;
+
+ GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
+ aGeomIndexes->length( aGroupIndexes.Length() );
+
+ for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
+ aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
+
+ aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
+ if ( aGroupOp->IsDone() )
+ {
+ SALOMEDS::SObject_var aGroupSO =
+ theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
+ }
+ }
+ }
+
+ return true;
+}
+#endif
+
+void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
+ const bool theIsSetToUpdate )
+{
+ TDF_Label aRulesLab = myLab.FindChild( theDataTag );
+ HYDROData_PriorityQueue::ClearRules( aRulesLab );
+
+ // Indicate model of the need to update splitting
+ if ( theIsSetToUpdate ) {
+ Changed( Geom_2d );
+ }
+}
+
+void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
+ HYDROData_PriorityType thePriority,
+ const Handle(HYDROData_Entity)& theObject2,
+ HYDROData_Zone::MergeType theMergeType,
+ HYDROData_CalculationCase::DataTag theDataTag )
+{
+ TDF_Label aRulesLab = myLab.FindChild( theDataTag );
+ HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
+
+ // Indicate model of the need to update splitting
+ Changed( Geom_2d );
+}
+
+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
+ Changed( Geom_2d );
+}
+
+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;
+}
+
+void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
+ const QString& theOldCaseName,
+ const QString& theName )
+{
+ HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ Handle(HYDROData_Region) aRegion =
+ Handle(HYDROData_Region)::DownCast( anIter.Value() );
+ if ( aRegion.IsNull() )
+ continue;
+
+ HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
+
+ HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
+ HYDROData_SequenceOfObjects::Iterator anIter( aZones );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ Handle(HYDROData_Zone) aRegZone =
+ Handle(HYDROData_Zone)::DownCast( anIter.Value() );
+ if ( aRegZone.IsNull() )
+ continue;
+
+ HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
+ }
+ }
+}
+
+void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
+ const QString& thePyScriptPath,
+ MapOfTreatedObjects& theTreatedObjects,
+ const HYDROData_SequenceOfObjects& theRegions ) const
+{
+ HYDROData_SequenceOfObjects::Iterator anIter;
+ anIter.Init(theRegions);
+ for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
+ {
+ Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
+ if (aRegion.IsNull())
+ continue;
+ QString defRegName = this->GetName();
+ QString regSuffix = QString("_Reg_%1").arg(ireg);
+ defRegName += regSuffix;
+ theTreatedObjects.insert(aRegion->GetName(), aRegion);
+ QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
+ theResList << aRegDump;
+ }
+ for (anIter.Init(theRegions); anIter.More(); anIter.Next())
+ {
+ Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
+ if (aRegion.IsNull())
+ continue;
+ QStringList aRegDump;
+ aRegion->SetNameInDumpPython(aRegDump);
+ theResList << aRegDump;
+ }
+}
+
+bool HYDROData_CalculationCase::GetRule( int theIndex,
+ Handle(HYDROData_Entity)& theObject1,
+ HYDROData_PriorityType& thePriority,
+ Handle(HYDROData_Entity)& theObject2,
+ HYDROData_Zone::MergeType& theMergeType,
+ HYDROData_CalculationCase::DataTag& theDataTag) const
+{
+ TDF_Label aRulesLab = myLab.FindChild( theDataTag );
+ return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
+ theObject1, thePriority, theObject2, theMergeType );
+}
+
+bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
+{
+ HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
+
+ if ( HasReference( theInterPolyline, aDataTag ) )
+ return false;
+
+ AddReferenceObject( theInterPolyline, aDataTag );
+
+ Changed( Geom_2d );
+
+ return true;
+}
+
+HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
+{
+ return GetReferenceObjects( DataTag_InterPoly );
+}
+
+void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline )
+{
+ if ( theInterPolyline.IsNull() )
+ return;
+
+ RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );
+
+ Changed( Geom_2d );
+}
+
+
+