2 #include "HYDROData_CalculationCase.h"
4 #include "HYDROData_ArtificialObject.h"
5 #include "HYDROData_IAltitudeObject.h"
6 #include "HYDROData_Document.h"
7 #include "HYDROData_ShapesGroup.h"
8 #include "HYDROData_Iterator.h"
9 #include "HYDROData_NaturalObject.h"
10 #include "HYDROData_PolylineXY.h"
11 #include "HYDROData_SplitToZonesTool.h"
12 #include "HYDROData_SplittedShapesGroup.h"
13 #include "HYDROData_Region.h"
14 #include "HYDROData_Tool.h"
15 #include "HYDROData_Zone.h"
22 #include <TopoDS_Shell.hxx>
23 #include <TopoDS_Edge.hxx>
25 #include <BRep_Builder.hxx>
26 #include <BRepBuilderAPI_Sewing.hxx>
27 #include <BRepTopAdaptor_FClass2d.hxx>
29 #include <BRepTools.hxx>
32 #include <TopExp_Explorer.hxx>
34 #include <TopTools_ListOfShape.hxx>
35 #include <TopTools_ListIteratorOfListOfShape.hxx>
37 //#define DEB_CALCULATION 1
38 #ifdef DEB_CALCULATION
39 #include <BRepTools.hxx>
40 #include <TopLoc_Location.hxx>
42 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
43 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
44 #define CALCULATION_GROUPS_PREF GetName() + "_"
46 #define EXPORT_NAME "HYDRO_" + GetName()
48 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
49 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
51 HYDROData_CalculationCase::HYDROData_CalculationCase()
56 HYDROData_CalculationCase::~HYDROData_CalculationCase()
60 void HYDROData_CalculationCase::SetName( const QString& theName )
62 QString anOldCaseName = GetName();
63 if ( anOldCaseName != theName )
65 HYDROData_SequenceOfObjects aRegions = GetRegions();
67 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
68 for ( ; anIter.More(); anIter.Next() )
70 Handle(HYDROData_Region) aRegion =
71 Handle(HYDROData_Region)::DownCast( anIter.Value() );
72 if ( aRegion.IsNull() )
75 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegion );
77 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
78 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
79 for ( ; anIter.More(); anIter.Next() )
81 Handle(HYDROData_Zone) aRegZone =
82 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
83 if ( aRegZone.IsNull() )
86 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegZone );
90 HYDROData_SequenceOfObjects aGroups = GetGeometryGroups();
92 anIter.Init( aGroups );
93 for ( ; anIter.More(); anIter.Next() )
95 Handle(HYDROData_SplittedShapesGroup) aGroup =
96 Handle(HYDROData_SplittedShapesGroup)::DownCast( anIter.Value() );
97 if ( aGroup.IsNull() )
100 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
104 HYDROData_Entity::SetName( theName );
107 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
109 QStringList aResList = dumpObjectCreation( theTreatedObjects );
110 QString aCalculName = GetName();
112 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
113 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
114 for ( ; anIter.More(); anIter.Next() )
116 Handle(HYDROData_Object) aRefGeomObj =
117 Handle(HYDROData_Object)::DownCast( anIter.Value() );
118 if ( !aRefGeomObj.IsNull() )
119 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
121 aResList << QString( "" );
123 aResList << QString( "%1.SplitGeometryObjects();" ).arg( aCalculName );
124 aResList << QString( "" );
126 // Now we restore the regions and zones order
127 HYDROData_SequenceOfObjects aRegions = GetRegions();
128 anIter.Init( aRegions );
129 for ( ; anIter.More(); anIter.Next() )
131 Handle(HYDROData_Region) aRegion =
132 Handle(HYDROData_Region)::DownCast( anIter.Value() );
133 if ( aRegion.IsNull() )
136 QString aRegionName = aRegion->GetName();
143 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
145 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
147 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
148 if ( !aBoundaryPolyline.IsNull() )
149 aResSeq.Append( aBoundaryPolyline );
151 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
152 aResSeq.Append( aSeqOfRegions );
157 void HYDROData_CalculationCase::Update()
159 HYDROData_Entity::Update();
161 // At first we remove previously created objects
163 RemoveSplittedGroups();
165 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
166 if ( aDocument.IsNull() )
169 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
170 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
171 if ( aGeomObjects.IsEmpty() )
174 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
176 HYDROData_SplitToZonesTool::SplitDataList aSplitedObjects =
177 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
178 if ( aSplitedObjects.isEmpty() )
181 QString aRegsPref = CALCULATION_REGIONS_PREF;
182 QString aZonesPref = CALCULATION_ZONES_PREF;
184 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
186 // Create result regions for case, by default one zone for one region
187 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedObjects );
188 while( anIter.hasNext() )
190 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
192 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
195 Handle(HYDROData_Region) aRegion = addNewRegion();
197 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
198 aRegion->SetName( aRegionName );
200 // Add the zone for region
201 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
203 QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref );
204 aRegionZone->SetName( aZoneName );
206 aRegionZone->SetShape( aSplitData.Face() );
208 // Add the reference object for zone
209 for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
211 const QString& anObjName = aSplitData.ObjectNames.at( i );
213 Handle(HYDROData_Object) aRefObject = Handle(HYDROData_Object)::DownCast(
214 HYDROData_Tool::FindObjectByName( aDocument, anObjName ) );
215 if ( aRefObject.IsNull() )
218 aRegionZone->AddGeometryObject( aRefObject );
221 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
223 // Create new edges group
224 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
227 QString anObjName = aSplitData.ObjectNames.first();
228 if ( anObjName.isEmpty() )
231 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
232 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
234 aSplittedGroup = addNewSplittedGroup();
236 QString aCalcGroupName = CALCULATION_GROUPS_PREF + anObjName;
237 aSplittedGroup->SetName( aCalcGroupName );
239 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
243 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
246 if ( aSplittedGroup.IsNull() )
249 aSplittedGroup->AddShape( aSplitData.Shape );
254 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
256 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
257 return false; // Wrong type of object
259 if ( HasReference( theObject, DataTag_GeometryObject ) )
260 return false; // Object is already in reference list
262 AddReferenceObject( theObject, DataTag_GeometryObject );
264 // Indicate model of the need to update splitting
270 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
272 return GetReferenceObjects( DataTag_GeometryObject );
275 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
277 if ( theObject.IsNull() )
280 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
282 // Indicate model of the need to update splitting
286 void HYDROData_CalculationCase::RemoveGeometryObjects()
288 ClearReferenceObjects( DataTag_GeometryObject );
290 // Indicate model of the need to update splitting
294 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
296 if ( theGroup.IsNull() )
299 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
300 return false; // Object is already in reference list
302 AddReferenceObject( theGroup, DataTag_GeometryGroup );
304 // Indicate model of the need to update splitting
310 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
312 return GetReferenceObjects( DataTag_GeometryGroup );
315 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
317 if ( theGroup.IsNull() )
320 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
322 // Indicate model of the need to update splitting
326 void HYDROData_CalculationCase::RemoveGeometryGroups()
328 ClearReferenceObjects( DataTag_GeometryGroup );
330 // Indicate model of the need to update splitting
334 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
336 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
338 SetReferenceObject( thePolyline, DataTag_Polyline );
340 // Indicate model of the need to update zones splitting
341 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
344 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
346 return Handle(HYDROData_PolylineXY)::DownCast(
347 GetReferenceObject( DataTag_Polyline ) );
350 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
352 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
354 ClearReferenceObjects( DataTag_Polyline );
356 // Indicate model of the need to update zones splitting
357 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
360 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
362 Handle(HYDROData_Region) aNewRegion = addNewRegion();
363 if ( aNewRegion.IsNull() )
366 // Generate new name for new region
367 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
368 if ( !aDocument.IsNull() )
370 QString aRegsPref = CALCULATION_REGIONS_PREF;
372 QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
373 aNewRegion->SetName( aNewRegionName );
376 aNewRegion->AddZone( theZone );
381 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
383 if ( theRegion.IsNull() )
386 if ( HasReference( theRegion, DataTag_Region ) )
387 return false; // Object is already in reference list
389 // Move the region from other calculation
390 Handle(HYDROData_CalculationCase) aFatherCalc =
391 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
392 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
394 Handle(HYDROData_Region) aNewRegion = addNewRegion();
395 theRegion->CopyTo( aNewRegion );
397 aFatherCalc->RemoveRegion( theRegion );
399 theRegion->SetLabel( aNewRegion->Label() );
403 AddReferenceObject( theRegion, DataTag_Region );
409 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
411 return GetReferenceObjects( DataTag_Region );
414 void HYDROData_CalculationCase::UpdateRegionsOrder()
416 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
417 if ( aDocument.IsNull() )
420 HYDROData_SequenceOfObjects aRegions = GetRegions();
422 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
423 for ( ; anIter.More(); anIter.Next() )
425 Handle(HYDROData_Region) aRegion =
426 Handle(HYDROData_Region)::DownCast( anIter.Value() );
427 if ( aRegion.IsNull() )
430 aRegion->SetName( "" );
433 QString aRegsPref = CALCULATION_REGIONS_PREF;
435 anIter.Init( aRegions );
436 for ( ; anIter.More(); anIter.Next() )
438 Handle(HYDROData_Region) aRegion =
439 Handle(HYDROData_Region)::DownCast( anIter.Value() );
440 if ( aRegion.IsNull() )
443 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
444 aRegion->SetName( aRegionName );
448 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
450 if ( theRegion.IsNull() )
453 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
455 // Remove region from data model
456 Handle(HYDROData_CalculationCase) aFatherCalc =
457 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
458 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
462 void HYDROData_CalculationCase::RemoveRegions()
464 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
467 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
469 return GetReferenceObjects( DataTag_SplittedGroups );
472 void HYDROData_CalculationCase::RemoveSplittedGroups()
474 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
477 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
479 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
481 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
482 if ( aZone.IsNull() )
485 HYDROData_Zone::MergeAltitudesType aZoneMergeType = aZone->GetMergeType();
486 if ( !aZone->IsMergingNeed() )
488 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
490 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
495 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
497 Handle(HYDROData_IAltitudeObject) aMergeAltitude = aZone->GetMergeAltitude();
498 if ( !aMergeAltitude.IsNull() )
499 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
503 HYDROData_SequenceOfObjects aZoneObjects = aZone->GetGeometryObjects();
504 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
505 for ( ; anIter.More(); anIter.Next() )
507 Handle(HYDROData_Object) aZoneObj =
508 Handle(HYDROData_Object)::DownCast( anIter.Value() );
509 if ( aZoneObj.IsNull() )
512 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
513 if ( anObjAltitude.IsNull() )
516 double aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
517 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
520 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
522 aResAltitude = aPointAltitude;
525 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
527 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
528 aResAltitude > aPointAltitude )
530 aResAltitude = aPointAltitude;
533 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
535 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
536 aResAltitude < aPointAltitude )
538 aResAltitude = aPointAltitude;
547 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
549 Handle(HYDROData_Zone) aResZone;
551 HYDROData_SequenceOfObjects aRegions = GetRegions();
553 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
554 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
556 Handle(HYDROData_Region) aRegion =
557 Handle(HYDROData_Region)::DownCast( anIter.Value() );
558 if ( aRegion.IsNull() )
561 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
562 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
563 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
565 Handle(HYDROData_Zone) aRegZone =
566 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
567 if ( aRegZone.IsNull() )
570 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
571 if ( aPointRelation != POINT_OUT )
572 aResZone = aRegZone; // We found the desired zone
579 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
580 const gp_XY& thePoint,
581 const Handle(HYDROData_Zone)& theZone ) const
583 PointClassification aRes = POINT_OUT;
584 if ( theZone.IsNull() )
587 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
588 if ( aZoneFace.IsNull() )
591 BRepTopAdaptor_FClass2d aClassifier( aZoneFace, Precision::Confusion() );
592 TopAbs_State State = aClassifier.Perform( gp_Pnt2d(thePoint), Standard_False );
593 if (State == TopAbs_OUT)
595 else if(State == TopAbs_IN)
597 else if(State == TopAbs_ON)
602 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion()
604 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
606 Handle(HYDROData_Region) aNewRegion =
607 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
608 AddRegion( aNewRegion );
613 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup()
615 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
617 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
618 Handle(HYDROData_SplittedShapesGroup)::DownCast(
619 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
620 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
625 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
626 SALOMEDS::Study_ptr theStudy ) const
628 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
630 // Get groups definitions
631 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
633 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
634 for ( ; anIter.More(); anIter.Next() )
637 Handle(HYDROData_ShapesGroup) aGroup =
638 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
639 if ( aGroup.IsNull() )
642 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
644 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
645 aGroup->GetShapes( aGroupDef.Shapes );
647 aSeqOfGroupsDefs.Append( aGroupDef );
651 TopTools_ListOfShape aFaces;
652 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
653 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
654 for ( ; aRegionIter.More(); aRegionIter.Next() )
656 Handle(HYDROData_Region) aRegion =
657 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
658 if( aRegion.IsNull() )
661 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
662 aFaces.Append( aRegionShape );
665 return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs );
668 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
669 SALOMEDS::Study_ptr theStudy,
670 const TopTools_ListOfShape& theFaces,
671 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs ) const
674 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
675 aSewing.SetNonManifoldMode( Standard_False );
676 #ifdef DEB_CALCULATION
677 TCollection_AsciiString aNam("Sh_");
680 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
681 for ( ; aFaceIter.More(); aFaceIter.Next() )
683 TopoDS_Shape aShape = aFaceIter.Value();
684 if ( aShape.IsNull() )
687 if ( aShape.ShapeType() == TopAbs_FACE )
689 aSewing.Add( aShape );
690 #ifdef DEB_CALCULATION
691 TCollection_AsciiString aName = aNam + ++i + ".brep";
692 BRepTools::Write(aShape ,aName.ToCString());
697 #ifdef DEB_CALCULATION
700 TopExp_Explorer anExp( aShape, TopAbs_FACE );
701 for (; anExp.More(); anExp.Next() ) {
702 aSewing.Add( anExp.Current() );
703 #ifdef DEB_CALCULATION
705 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
706 BRepTools::Write(anExp.Current() ,aName.ToCString());
713 TopoDS_Shape aSewedShape = aSewing.SewedShape();
715 // If the sewed shape is empty - return false
716 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
719 #ifdef DEB_CALCULATION
720 BRepTools::Write(aSewedShape ,"Sew.brep");
722 // Publish the sewed shape
723 QString aName = EXPORT_NAME;
724 GEOM::GEOM_Object_ptr aMainShape =
725 publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName );
727 if ( aMainShape->_is_nil() )
730 if ( theGroupsDefs.IsEmpty() )
734 TopTools_IndexedMapOfShape aMapOfSubShapes;
735 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
737 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
739 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
741 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
743 NCollection_Sequence<int> aGroupIndexes;
744 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
746 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
747 #ifdef DEB_CALCULATION
748 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
750 const TopoDS_Shape& aModifiedShape = aSewing.Modified( aShape );
751 if ( aModifiedShape.IsNull() )
754 #ifdef DEB_CALCULATION
755 const TopLoc_Location& aL1 = aShape.Location();
756 const TopLoc_Location& aL2 = aModifiedShape.Location();
757 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
760 // Workaround for TopTools_IndexedMapOfShape::FindIndex()
761 /*for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
763 if ( aModifiedShape.IsPartner( aMapOfSubShapes.FindKey( anIndex ) ) )
765 aGroupIndexes.Append( anIndex );
770 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
772 aGroupIndexes.Append( anIndex );
775 #ifdef DEB_CALCULATION
776 TCollection_AsciiString aNam("Lost_");
777 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
778 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
780 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
781 if ( aModifiedShape.IsPartner( aS ) )
783 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
784 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
785 BRepTools::Write(aS ,aName.ToCString());
793 if ( !aGroupIndexes.IsEmpty() )
794 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
797 if ( !aGroupsData.IsEmpty() )
799 GEOM::GEOM_IGroupOperations_var aGroupOp =
800 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
802 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
803 for ( ; aMapIt.More(); aMapIt.Next() )
805 const TCollection_AsciiString& aGroupName = aMapIt.Key();
806 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
808 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
809 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
812 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
813 aGeomIndexes->length( aGroupIndexes.Length() );
815 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
816 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
818 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
819 if ( aGroupOp->IsDone() )
821 SALOMEDS::SObject_var aGroupSO =
822 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
830 GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
831 GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
832 const TopoDS_Shape& theShape, const QString& theName ) const
834 GEOM::GEOM_Object_var aGeomObj;
836 if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
837 theShape.IsNull() ) {
838 return aGeomObj._retn();
841 std::ostringstream aStreamShape;
842 // Write TopoDS_Shape in ASCII format to the stream
843 BRepTools::Write( theShape, aStreamShape );
844 // Returns the number of bytes that have been stored in the stream's buffer.
845 int aSize = aStreamShape.str().size();
846 // Allocate octect buffer of required size
847 CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
848 // Copy ostrstream content to the octect buffer
849 memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
851 SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
853 // Restore shape from the stream and get the GEOM object
854 GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
855 aGeomObj = anInsOp->RestoreShape( aSeqFile );
857 // Puplish the GEOM object
858 if ( !aGeomObj->_is_nil() ) {
859 QString aName = GEOMBase::GetDefaultName( theName );
861 SALOMEDS::SObject_var aResultSO =
862 theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
863 aGeomObj, qPrintable( aName ) );
864 if ( aResultSO->_is_nil() ) {
865 aGeomObj = GEOM::GEOM_Object::_nil();
869 return aGeomObj._retn();