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 = GetObjPyName();
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();
140 aResList << QString( "" );
141 aResList << QString( "%1.Update();" ).arg( aCalculName );
142 aResList << QString( "" );
147 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
149 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
151 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
152 if ( !aBoundaryPolyline.IsNull() )
153 aResSeq.Append( aBoundaryPolyline );
155 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
156 aResSeq.Append( aSeqOfRegions );
161 void HYDROData_CalculationCase::Update()
163 HYDROData_Entity::Update();
165 // At first we remove previously created objects
167 RemoveSplittedGroups();
169 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
170 if ( aDocument.IsNull() )
173 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
174 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
175 if ( aGeomObjects.IsEmpty() )
178 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
180 HYDROData_SplitToZonesTool::SplitDataList aSplitedObjects =
181 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
182 if ( aSplitedObjects.isEmpty() )
185 QString aRegsPref = CALCULATION_REGIONS_PREF;
186 QString aZonesPref = CALCULATION_ZONES_PREF;
188 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
190 // Create result regions for case, by default one zone for one region
191 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedObjects );
192 while( anIter.hasNext() )
194 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
196 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
199 Handle(HYDROData_Region) aRegion = addNewRegion();
201 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
202 aRegion->SetName( aRegionName );
204 // Add the zone for region
205 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
207 QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref );
208 aRegionZone->SetName( aZoneName );
210 aRegionZone->SetShape( aSplitData.Face() );
212 // Add the reference object for zone
213 for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
215 const QString& anObjName = aSplitData.ObjectNames.at( i );
217 Handle(HYDROData_Object) aRefObject = Handle(HYDROData_Object)::DownCast(
218 HYDROData_Tool::FindObjectByName( aDocument, anObjName ) );
219 if ( aRefObject.IsNull() )
222 aRegionZone->AddGeometryObject( aRefObject );
225 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
227 // Create new edges group
228 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
231 QString anObjName = aSplitData.ObjectNames.first();
232 if ( anObjName.isEmpty() )
235 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
236 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
238 aSplittedGroup = addNewSplittedGroup();
240 QString aCalcGroupName = CALCULATION_GROUPS_PREF + anObjName;
241 aSplittedGroup->SetName( aCalcGroupName );
243 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
247 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
250 if ( aSplittedGroup.IsNull() )
253 aSplittedGroup->AddShape( aSplitData.Shape );
258 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
260 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
261 return false; // Wrong type of object
263 if ( HasReference( theObject, DataTag_GeometryObject ) )
264 return false; // Object is already in reference list
266 AddReferenceObject( theObject, DataTag_GeometryObject );
268 // Indicate model of the need to update splitting
274 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
276 return GetReferenceObjects( DataTag_GeometryObject );
279 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
281 if ( theObject.IsNull() )
284 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
286 // Indicate model of the need to update splitting
290 void HYDROData_CalculationCase::RemoveGeometryObjects()
292 ClearReferenceObjects( DataTag_GeometryObject );
294 // Indicate model of the need to update splitting
298 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
300 if ( theGroup.IsNull() )
303 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
304 return false; // Object is already in reference list
306 AddReferenceObject( theGroup, DataTag_GeometryGroup );
308 // Indicate model of the need to update splitting
314 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
316 return GetReferenceObjects( DataTag_GeometryGroup );
319 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
321 if ( theGroup.IsNull() )
324 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
326 // Indicate model of the need to update splitting
330 void HYDROData_CalculationCase::RemoveGeometryGroups()
332 ClearReferenceObjects( DataTag_GeometryGroup );
334 // Indicate model of the need to update splitting
338 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
340 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
342 SetReferenceObject( thePolyline, DataTag_Polyline );
344 // Indicate model of the need to update zones splitting
345 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
348 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
350 return Handle(HYDROData_PolylineXY)::DownCast(
351 GetReferenceObject( DataTag_Polyline ) );
354 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
356 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
358 ClearReferenceObjects( DataTag_Polyline );
360 // Indicate model of the need to update zones splitting
361 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
364 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
366 Handle(HYDROData_Region) aNewRegion = addNewRegion();
367 if ( aNewRegion.IsNull() )
370 // Generate new name for new region
371 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
372 if ( !aDocument.IsNull() )
374 QString aRegsPref = CALCULATION_REGIONS_PREF;
376 QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
377 aNewRegion->SetName( aNewRegionName );
380 aNewRegion->AddZone( theZone );
385 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
387 if ( theRegion.IsNull() )
390 if ( HasReference( theRegion, DataTag_Region ) )
391 return false; // Object is already in reference list
393 // Move the region from other calculation
394 Handle(HYDROData_CalculationCase) aFatherCalc =
395 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
396 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
398 Handle(HYDROData_Region) aNewRegion = addNewRegion();
399 theRegion->CopyTo( aNewRegion );
401 aFatherCalc->RemoveRegion( theRegion );
403 theRegion->SetLabel( aNewRegion->Label() );
407 AddReferenceObject( theRegion, DataTag_Region );
413 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
415 return GetReferenceObjects( DataTag_Region );
418 void HYDROData_CalculationCase::UpdateRegionsOrder()
420 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
421 if ( aDocument.IsNull() )
424 HYDROData_SequenceOfObjects aRegions = GetRegions();
426 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
427 for ( ; anIter.More(); anIter.Next() )
429 Handle(HYDROData_Region) aRegion =
430 Handle(HYDROData_Region)::DownCast( anIter.Value() );
431 if ( aRegion.IsNull() )
434 aRegion->SetName( "" );
437 QString aRegsPref = CALCULATION_REGIONS_PREF;
439 anIter.Init( aRegions );
440 for ( ; anIter.More(); anIter.Next() )
442 Handle(HYDROData_Region) aRegion =
443 Handle(HYDROData_Region)::DownCast( anIter.Value() );
444 if ( aRegion.IsNull() )
447 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
448 aRegion->SetName( aRegionName );
452 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
454 if ( theRegion.IsNull() )
457 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
459 // Remove region from data model
460 Handle(HYDROData_CalculationCase) aFatherCalc =
461 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
462 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
466 void HYDROData_CalculationCase::RemoveRegions()
468 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
471 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
473 return GetReferenceObjects( DataTag_SplittedGroups );
476 void HYDROData_CalculationCase::RemoveSplittedGroups()
478 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
481 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
483 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
485 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
486 if ( aZone.IsNull() )
489 HYDROData_Zone::MergeAltitudesType aZoneMergeType = aZone->GetMergeType();
490 if ( !aZone->IsMergingNeed() )
492 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
494 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
499 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
501 Handle(HYDROData_IAltitudeObject) aMergeAltitude = aZone->GetMergeAltitude();
502 if ( !aMergeAltitude.IsNull() )
503 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
507 HYDROData_SequenceOfObjects aZoneObjects = aZone->GetGeometryObjects();
508 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
509 for ( ; anIter.More(); anIter.Next() )
511 Handle(HYDROData_Object) aZoneObj =
512 Handle(HYDROData_Object)::DownCast( anIter.Value() );
513 if ( aZoneObj.IsNull() )
516 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
517 if ( anObjAltitude.IsNull() )
520 double aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
521 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
524 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
526 aResAltitude = aPointAltitude;
529 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
531 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
532 aResAltitude > aPointAltitude )
534 aResAltitude = aPointAltitude;
537 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
539 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
540 aResAltitude < aPointAltitude )
542 aResAltitude = aPointAltitude;
551 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
553 Handle(HYDROData_Zone) aResZone;
555 HYDROData_SequenceOfObjects aRegions = GetRegions();
557 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
558 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
560 Handle(HYDROData_Region) aRegion =
561 Handle(HYDROData_Region)::DownCast( anIter.Value() );
562 if ( aRegion.IsNull() )
565 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
566 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
567 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
569 Handle(HYDROData_Zone) aRegZone =
570 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
571 if ( aRegZone.IsNull() )
574 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
575 if ( aPointRelation != POINT_OUT )
576 aResZone = aRegZone; // We found the desired zone
583 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
584 const gp_XY& thePoint,
585 const Handle(HYDROData_Zone)& theZone ) const
587 PointClassification aRes = POINT_OUT;
588 if ( theZone.IsNull() )
591 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
592 if ( aZoneFace.IsNull() )
595 BRepTopAdaptor_FClass2d aClassifier( aZoneFace, Precision::Confusion() );
596 TopAbs_State State = aClassifier.Perform( gp_Pnt2d(thePoint), Standard_False );
597 if (State == TopAbs_OUT)
599 else if(State == TopAbs_IN)
601 else if(State == TopAbs_ON)
606 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion()
608 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
610 Handle(HYDROData_Region) aNewRegion =
611 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
612 AddRegion( aNewRegion );
617 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup()
619 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
621 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
622 Handle(HYDROData_SplittedShapesGroup)::DownCast(
623 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
624 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
629 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
630 SALOMEDS::Study_ptr theStudy ) const
632 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
634 // Get groups definitions
635 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
637 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
638 for ( ; anIter.More(); anIter.Next() )
641 Handle(HYDROData_ShapesGroup) aGroup =
642 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
643 if ( aGroup.IsNull() )
646 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
648 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
649 aGroup->GetShapes( aGroupDef.Shapes );
651 aSeqOfGroupsDefs.Append( aGroupDef );
655 TopTools_ListOfShape aFaces;
656 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
657 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
658 for ( ; aRegionIter.More(); aRegionIter.Next() )
660 Handle(HYDROData_Region) aRegion =
661 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
662 if( aRegion.IsNull() )
665 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
666 aFaces.Append( aRegionShape );
669 return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs );
672 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
673 SALOMEDS::Study_ptr theStudy,
674 const TopTools_ListOfShape& theFaces,
675 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs ) const
678 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
679 aSewing.SetNonManifoldMode( Standard_False );
680 #ifdef DEB_CALCULATION
681 TCollection_AsciiString aNam("Sh_");
684 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
685 for ( ; aFaceIter.More(); aFaceIter.Next() )
687 TopoDS_Shape aShape = aFaceIter.Value();
688 if ( aShape.IsNull() )
691 if ( aShape.ShapeType() == TopAbs_FACE )
693 aSewing.Add( aShape );
694 #ifdef DEB_CALCULATION
695 TCollection_AsciiString aName = aNam + ++i + ".brep";
696 BRepTools::Write(aShape ,aName.ToCString());
701 #ifdef DEB_CALCULATION
704 TopExp_Explorer anExp( aShape, TopAbs_FACE );
705 for (; anExp.More(); anExp.Next() ) {
706 aSewing.Add( anExp.Current() );
707 #ifdef DEB_CALCULATION
709 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
710 BRepTools::Write(anExp.Current() ,aName.ToCString());
717 TopoDS_Shape aSewedShape = aSewing.SewedShape();
719 // If the sewed shape is empty - return false
720 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
723 #ifdef DEB_CALCULATION
724 BRepTools::Write(aSewedShape ,"Sew.brep");
726 // Publish the sewed shape
727 QString aName = EXPORT_NAME;
728 GEOM::GEOM_Object_ptr aMainShape =
729 publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName );
731 if ( aMainShape->_is_nil() )
734 if ( theGroupsDefs.IsEmpty() )
738 TopTools_IndexedMapOfShape aMapOfSubShapes;
739 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
741 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
743 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
745 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
747 NCollection_Sequence<int> aGroupIndexes;
748 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
750 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
751 #ifdef DEB_CALCULATION
752 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
754 const TopoDS_Shape& aModifiedShape = aSewing.Modified( aShape );
755 if ( aModifiedShape.IsNull() )
758 #ifdef DEB_CALCULATION
759 const TopLoc_Location& aL1 = aShape.Location();
760 const TopLoc_Location& aL2 = aModifiedShape.Location();
761 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
764 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
766 aGroupIndexes.Append( anIndex );
768 #ifdef DEB_CALCULATION
769 TCollection_AsciiString aNam("Lost_");
770 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
771 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
773 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
774 if ( aModifiedShape.IsPartner( aS ) )
776 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
777 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
778 BRepTools::Write(aS ,aName.ToCString());
786 if ( !aGroupIndexes.IsEmpty() )
787 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
790 if ( !aGroupsData.IsEmpty() )
792 GEOM::GEOM_IGroupOperations_var aGroupOp =
793 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
795 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
796 for ( ; aMapIt.More(); aMapIt.Next() )
798 const TCollection_AsciiString& aGroupName = aMapIt.Key();
799 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
801 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
802 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
805 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
806 aGeomIndexes->length( aGroupIndexes.Length() );
808 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
809 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
811 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
812 if ( aGroupOp->IsDone() )
814 SALOMEDS::SObject_var aGroupSO =
815 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
823 GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
824 GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
825 const TopoDS_Shape& theShape, const QString& theName ) const
827 GEOM::GEOM_Object_var aGeomObj;
829 if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
830 theShape.IsNull() ) {
831 return aGeomObj._retn();
834 std::ostringstream aStreamShape;
835 // Write TopoDS_Shape in ASCII format to the stream
836 BRepTools::Write( theShape, aStreamShape );
837 // Returns the number of bytes that have been stored in the stream's buffer.
838 int aSize = aStreamShape.str().size();
839 // Allocate octect buffer of required size
840 CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
841 // Copy ostrstream content to the octect buffer
842 memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
844 SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
846 // Restore shape from the stream and get the GEOM object
847 GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
848 aGeomObj = anInsOp->RestoreShape( aSeqFile );
850 // Puplish the GEOM object
851 if ( !aGeomObj->_is_nil() ) {
852 QString aName = GEOMBase::GetDefaultName( theName );
854 SALOMEDS::SObject_var aResultSO =
855 theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
856 aGeomObj, qPrintable( aName ) );
857 if ( aResultSO->_is_nil() ) {
858 aGeomObj = GEOM::GEOM_Object::_nil();
862 return aGeomObj._retn();