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() + "_"
45 //#define DEB_CLASS2D 1
47 #include <BRepBuilderAPI_MakeVertex.hxx>
50 #define EXPORT_NAME "HYDRO_" + GetName()
52 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
53 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
55 HYDROData_CalculationCase::HYDROData_CalculationCase()
60 HYDROData_CalculationCase::~HYDROData_CalculationCase()
64 void HYDROData_CalculationCase::SetName( const QString& theName )
66 QString anOldCaseName = GetName();
67 if ( anOldCaseName != theName )
69 HYDROData_SequenceOfObjects aRegions = GetRegions();
71 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
72 for ( ; anIter.More(); anIter.Next() )
74 Handle(HYDROData_Region) aRegion =
75 Handle(HYDROData_Region)::DownCast( anIter.Value() );
76 if ( aRegion.IsNull() )
79 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegion );
81 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
82 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
83 for ( ; anIter.More(); anIter.Next() )
85 Handle(HYDROData_Zone) aRegZone =
86 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
87 if ( aRegZone.IsNull() )
90 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegZone );
94 HYDROData_SequenceOfObjects aGroups = GetSplittedGroups();
96 anIter.Init( aGroups );
97 for ( ; anIter.More(); anIter.Next() )
99 Handle(HYDROData_SplittedShapesGroup) aGroup =
100 Handle(HYDROData_SplittedShapesGroup)::DownCast( anIter.Value() );
101 if ( aGroup.IsNull() )
104 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
108 HYDROData_Entity::SetName( theName );
111 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
113 QStringList aResList = dumpObjectCreation( theTreatedObjects );
115 QString aCalculName = GetObjPyName();
117 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
118 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
119 for ( ; anIter.More(); anIter.Next() )
121 Handle(HYDROData_Object) aRefGeomObj =
122 Handle(HYDROData_Object)::DownCast( anIter.Value() );
123 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
125 aResList << QString( "" );
127 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
129 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
130 anIter.Init( aGeomGroups );
131 for ( ; anIter.More(); anIter.Next() )
133 Handle(HYDROData_ShapesGroup) aGeomGroup =
134 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
135 if ( aGeomGroup.IsNull() )
138 Handle(HYDROData_Object) aFatherGeom =
139 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
140 if ( aFatherGeom.IsNull() )
143 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
144 aResList << QString( "%1 = %2.GetGroup( %3 );" )
145 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
147 aResList << QString( "%1.AddGeometryGroup( %2 );" ).arg( aCalculName ).arg( aGroupName );
149 aResList << QString( "" );
151 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
152 setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
153 aResList << QString( "" );
155 aResList << QString( "%1.Update();" ).arg( aCalculName );
156 aResList << QString( "" );
158 // Now we restore the regions and zones order
159 HYDROData_SequenceOfObjects aRegions = GetRegions();
160 anIter.Init( aRegions );
161 for ( ; anIter.More(); anIter.Next() )
163 Handle(HYDROData_Region) aRegion =
164 Handle(HYDROData_Region)::DownCast( anIter.Value() );
165 if ( aRegion.IsNull() )
168 QString aRegionName = aRegion->GetName();
170 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
171 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
172 for ( ; aZonesIter.More(); aZonesIter.Next() )
174 Handle(HYDROData_Zone) aRegZone =
175 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
176 if ( aRegZone.IsNull() )
182 aResList << QString( "" );
187 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
189 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
191 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
192 if ( !aBoundaryPolyline.IsNull() )
193 aResSeq.Append( aBoundaryPolyline );
195 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
196 aResSeq.Append( aSeqOfRegions );
201 void HYDROData_CalculationCase::Update()
203 HYDROData_Entity::Update();
205 // At first we remove previously created objects
207 RemoveSplittedGroups();
209 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
210 if ( aDocument.IsNull() )
213 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
214 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
215 if ( aGeomObjects.IsEmpty() )
218 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
220 HYDROData_SplitToZonesTool::SplitDataList aSplitedObjects =
221 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
222 if ( aSplitedObjects.isEmpty() )
225 QString aRegsPref = CALCULATION_REGIONS_PREF;
226 QString aZonesPref = CALCULATION_ZONES_PREF;
228 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
230 // Create result regions for case, by default one zone for one region
231 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedObjects );
232 while( anIter.hasNext() )
234 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
236 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
239 Handle(HYDROData_Region) aRegion = addNewRegion();
241 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
242 aRegion->SetName( aRegionName );
244 // Add the zone for region
245 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
247 QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref );
248 aRegionZone->SetName( aZoneName );
250 aRegionZone->SetShape( aSplitData.Face() );
252 // Add the reference object for zone
253 for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
255 const QString& anObjName = aSplitData.ObjectNames.at( i );
257 Handle(HYDROData_Object) aRefObject =
258 Handle(HYDROData_Object)::DownCast( aDocument->FindObjectByName( anObjName ) );
259 if ( aRefObject.IsNull() )
262 aRegionZone->AddGeometryObject( aRefObject );
265 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
267 // Create new edges group
268 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
271 QString anObjName = aSplitData.ObjectNames.first();
272 if ( anObjName.isEmpty() )
274 #ifdef DEB_CALCULATION
275 QString aStr = aSplitData.ObjectNames.join(" ");
276 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
278 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
279 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
281 aSplittedGroup = addNewSplittedGroup();
283 QString aCalcGroupName = CALCULATION_GROUPS_PREF + anObjName;
284 aSplittedGroup->SetName( aCalcGroupName );
286 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
290 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
293 if ( aSplittedGroup.IsNull() )
296 aSplittedGroup->AddShape( aSplitData.Shape );
301 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
303 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
304 return false; // Wrong type of object
306 if ( HasReference( theObject, DataTag_GeometryObject ) )
307 return false; // Object is already in reference list
309 AddReferenceObject( theObject, DataTag_GeometryObject );
311 // Indicate model of the need to update splitting
317 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
319 return GetReferenceObjects( DataTag_GeometryObject );
322 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
324 if ( theObject.IsNull() )
327 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
329 // Indicate model of the need to update splitting
333 void HYDROData_CalculationCase::RemoveGeometryObjects()
335 ClearReferenceObjects( DataTag_GeometryObject );
337 // Indicate model of the need to update splitting
341 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
343 if ( theGroup.IsNull() )
346 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
347 return false; // Object is already in reference list
349 AddReferenceObject( theGroup, DataTag_GeometryGroup );
351 // Indicate model of the need to update splitting
357 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
359 return GetReferenceObjects( DataTag_GeometryGroup );
362 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
364 if ( theGroup.IsNull() )
367 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
369 // Indicate model of the need to update splitting
373 void HYDROData_CalculationCase::RemoveGeometryGroups()
375 ClearReferenceObjects( DataTag_GeometryGroup );
377 // Indicate model of the need to update splitting
381 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
383 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
385 SetReferenceObject( thePolyline, DataTag_Polyline );
387 // Indicate model of the need to update zones splitting
388 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
391 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
393 return Handle(HYDROData_PolylineXY)::DownCast(
394 GetReferenceObject( DataTag_Polyline ) );
397 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
399 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
401 ClearReferenceObjects( DataTag_Polyline );
403 // Indicate model of the need to update zones splitting
404 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
407 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
409 Handle(HYDROData_Region) aNewRegion = addNewRegion();
410 if ( aNewRegion.IsNull() )
413 // Generate new name for new region
414 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
415 if ( !aDocument.IsNull() )
417 QString aRegsPref = CALCULATION_REGIONS_PREF;
419 QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
420 aNewRegion->SetName( aNewRegionName );
423 aNewRegion->AddZone( theZone );
428 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
430 if ( theRegion.IsNull() )
433 if ( HasReference( theRegion, DataTag_Region ) )
434 return false; // Object is already in reference list
436 // Move the region from other calculation
437 Handle(HYDROData_CalculationCase) aFatherCalc =
438 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
439 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
441 Handle(HYDROData_Region) aNewRegion = addNewRegion();
442 theRegion->CopyTo( aNewRegion );
444 aFatherCalc->RemoveRegion( theRegion );
446 theRegion->SetLabel( aNewRegion->Label() );
450 AddReferenceObject( theRegion, DataTag_Region );
456 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
458 return GetReferenceObjects( DataTag_Region );
461 void HYDROData_CalculationCase::UpdateRegionsOrder()
463 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
464 if ( aDocument.IsNull() )
467 HYDROData_SequenceOfObjects aRegions = GetRegions();
469 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
470 for ( ; anIter.More(); anIter.Next() )
472 Handle(HYDROData_Region) aRegion =
473 Handle(HYDROData_Region)::DownCast( anIter.Value() );
474 if ( aRegion.IsNull() )
477 aRegion->SetName( "" );
480 QString aRegsPref = CALCULATION_REGIONS_PREF;
482 anIter.Init( aRegions );
483 for ( ; anIter.More(); anIter.Next() )
485 Handle(HYDROData_Region) aRegion =
486 Handle(HYDROData_Region)::DownCast( anIter.Value() );
487 if ( aRegion.IsNull() )
490 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
491 aRegion->SetName( aRegionName );
495 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
497 if ( theRegion.IsNull() )
500 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
502 // Remove region from data model
503 Handle(HYDROData_CalculationCase) aFatherCalc =
504 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
505 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
509 void HYDROData_CalculationCase::RemoveRegions()
511 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
514 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
516 return GetReferenceObjects( DataTag_SplittedGroups );
519 void HYDROData_CalculationCase::RemoveSplittedGroups()
521 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
524 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
526 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
527 return GetAltitudeForPoint( thePoint, aZone );
530 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
531 const Handle(HYDROData_Region)& theRegion ) const
533 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
535 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
536 if ( !aZone.IsNull() )
538 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
539 if ( IsEqual( aRefRegion, theRegion ) )
540 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
546 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
547 const Handle(HYDROData_Zone)& theZone ) const
549 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
550 if ( theZone.IsNull() )
553 HYDROData_Zone::MergeAltitudesType aZoneMergeType = theZone->GetMergeType();
554 if ( !theZone->IsMergingNeed() )
556 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
558 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
563 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
564 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
566 Handle(HYDROData_IAltitudeObject) aMergeAltitude = theZone->GetMergeAltitude();
567 if ( !aMergeAltitude.IsNull() )
569 if ( aZoneInterpolator != NULL )
571 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
572 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
575 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
580 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetGeometryObjects();
581 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
582 for ( ; anIter.More(); anIter.Next() )
584 Handle(HYDROData_Object) aZoneObj =
585 Handle(HYDROData_Object)::DownCast( anIter.Value() );
586 if ( aZoneObj.IsNull() )
589 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
590 if ( anObjAltitude.IsNull() )
593 double aPointAltitude = 0.0;
594 if ( aZoneInterpolator != NULL )
596 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
597 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
600 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
602 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
605 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
607 aResAltitude = aPointAltitude;
610 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
612 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
613 aResAltitude > aPointAltitude )
615 aResAltitude = aPointAltitude;
618 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
620 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
621 aResAltitude < aPointAltitude )
623 aResAltitude = aPointAltitude;
632 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
633 const NCollection_Sequence<gp_XY>& thePoints,
634 const Handle(HYDROData_Region)& theRegion ) const
636 NCollection_Sequence<double> aResSeq;
638 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
640 const gp_XY& thePnt = thePoints.Value( i );
642 double anAltitude = GetAltitudeForPoint( thePnt, theRegion );
643 aResSeq.Append( anAltitude );
649 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
650 const NCollection_Sequence<gp_XY>& thePoints,
651 const Handle(HYDROData_Zone)& theZone ) const
653 NCollection_Sequence<double> aResSeq;
655 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
657 const gp_XY& thePnt = thePoints.Value( i );
659 double anAltitude = GetAltitudeForPoint( thePnt, theZone );
660 aResSeq.Append( anAltitude );
666 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
668 Handle(HYDROData_Region) aResRegion;
670 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
671 if ( !aZone.IsNull() )
672 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
677 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
679 Handle(HYDROData_Zone) aResZone;
681 HYDROData_SequenceOfObjects aRegions = GetRegions();
683 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
684 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
686 Handle(HYDROData_Region) aRegion =
687 Handle(HYDROData_Region)::DownCast( anIter.Value() );
688 if ( aRegion.IsNull() )
691 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
692 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
693 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
695 Handle(HYDROData_Zone) aRegZone =
696 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
697 if ( aRegZone.IsNull() )
700 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
701 if ( aPointRelation != POINT_OUT )
702 aResZone = aRegZone; // We found the desired zone
709 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
710 const gp_XY& thePoint,
711 const Handle(HYDROData_Zone)& theZone ) const
713 PointClassification aRes = POINT_OUT;
714 if ( theZone.IsNull() )
717 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
718 if ( aZoneFace.IsNull() )
721 TopoDS_Compound aCmp;
723 aBB.MakeCompound(aCmp);
724 aBB.Add(aCmp, aZoneFace);
725 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
726 BRepBuilderAPI_MakeVertex aMk(aPnt);
727 aBB.Add(aCmp, aMk.Vertex());
728 BRepTools::Write(aCmp, "FCL2d.brep");
730 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
731 if (State == TopAbs_OUT)
733 else if(State == TopAbs_IN)
735 else if(State == TopAbs_ON)
740 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion()
742 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
744 Handle(HYDROData_Region) aNewRegion =
745 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
746 AddRegion( aNewRegion );
751 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup()
753 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
755 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
756 Handle(HYDROData_SplittedShapesGroup)::DownCast(
757 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
758 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
763 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
764 SALOMEDS::Study_ptr theStudy ) const
766 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
768 // Get groups definitions
769 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
771 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
772 for ( ; anIter.More(); anIter.Next() )
775 Handle(HYDROData_ShapesGroup) aGroup =
776 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
777 if ( aGroup.IsNull() )
780 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
782 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
783 aGroup->GetShapes( aGroupDef.Shapes );
785 aSeqOfGroupsDefs.Append( aGroupDef );
789 TopTools_ListOfShape aFaces;
790 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
791 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
792 for ( ; aRegionIter.More(); aRegionIter.Next() )
794 Handle(HYDROData_Region) aRegion =
795 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
796 if( aRegion.IsNull() )
799 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
800 aFaces.Append( aRegionShape );
803 return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs );
806 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
807 SALOMEDS::Study_ptr theStudy,
808 const TopTools_ListOfShape& theFaces,
809 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs ) const
812 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
813 aSewing.SetNonManifoldMode( Standard_False );
814 #ifdef DEB_CALCULATION
815 TCollection_AsciiString aNam("Sh_");
818 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
819 for ( ; aFaceIter.More(); aFaceIter.Next() )
821 TopoDS_Shape aShape = aFaceIter.Value();
822 if ( aShape.IsNull() )
825 if ( aShape.ShapeType() == TopAbs_FACE )
827 aSewing.Add( aShape );
828 #ifdef DEB_CALCULATION
829 TCollection_AsciiString aName = aNam + ++i + ".brep";
830 BRepTools::Write(aShape ,aName.ToCString());
835 #ifdef DEB_CALCULATION
838 TopExp_Explorer anExp( aShape, TopAbs_FACE );
839 for (; anExp.More(); anExp.Next() ) {
840 aSewing.Add( anExp.Current() );
841 #ifdef DEB_CALCULATION
843 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
844 BRepTools::Write(anExp.Current() ,aName.ToCString());
851 TopoDS_Shape aSewedShape = aSewing.SewedShape();
853 // If the sewed shape is empty - return false
854 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
857 #ifdef DEB_CALCULATION
858 BRepTools::Write(aSewedShape ,"Sew.brep");
860 // Publish the sewed shape
861 QString aName = EXPORT_NAME;
862 GEOM::GEOM_Object_ptr aMainShape =
863 publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName );
865 if ( aMainShape->_is_nil() )
868 if ( theGroupsDefs.IsEmpty() )
872 TopTools_IndexedMapOfShape aMapOfSubShapes;
873 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
875 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
877 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
879 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
881 NCollection_Sequence<int> aGroupIndexes;
882 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
884 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
885 #ifdef DEB_CALCULATION
886 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
889 TopoDS_Shape aModifiedShape = aShape;
890 if ( aSewing.IsModified( aShape ) )
891 aModifiedShape = aSewing.Modified( aShape );
892 else if ( aSewing.IsModifiedSubShape( aShape ) )
893 aModifiedShape = aSewing.ModifiedSubShape( aShape );
895 #ifdef DEB_CALCULATION
896 const TopLoc_Location& aL1 = aShape.Location();
897 const TopLoc_Location& aL2 = aModifiedShape.Location();
898 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
901 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
903 aGroupIndexes.Append( anIndex );
905 #ifdef DEB_CALCULATION
906 TCollection_AsciiString aNam("Lost_");
907 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
908 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
910 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
911 if ( aModifiedShape.IsPartner( aS ) )
913 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
914 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
915 BRepTools::Write(aS ,aName.ToCString());
923 if ( !aGroupIndexes.IsEmpty() )
924 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
927 if ( !aGroupsData.IsEmpty() )
929 GEOM::GEOM_IGroupOperations_var aGroupOp =
930 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
932 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
933 for ( ; aMapIt.More(); aMapIt.Next() )
935 const TCollection_AsciiString& aGroupName = aMapIt.Key();
936 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
938 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
939 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
942 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
943 aGeomIndexes->length( aGroupIndexes.Length() );
945 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
946 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
948 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
949 if ( aGroupOp->IsDone() )
951 SALOMEDS::SObject_var aGroupSO =
952 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
960 GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
961 GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
962 const TopoDS_Shape& theShape, const QString& theName ) const
964 GEOM::GEOM_Object_var aGeomObj;
966 if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
967 theShape.IsNull() ) {
968 return aGeomObj._retn();
971 std::ostringstream aStreamShape;
972 // Write TopoDS_Shape in ASCII format to the stream
973 BRepTools::Write( theShape, aStreamShape );
974 // Returns the number of bytes that have been stored in the stream's buffer.
975 int aSize = aStreamShape.str().size();
976 // Allocate octect buffer of required size
977 CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
978 // Copy ostrstream content to the octect buffer
979 memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
981 SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
983 // Restore shape from the stream and get the GEOM object
984 GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
985 aGeomObj = anInsOp->RestoreShape( aSeqFile );
987 // Puplish the GEOM object
988 if ( !aGeomObj->_is_nil() ) {
989 QString aName = GEOMBase::GetDefaultName( theName );
991 SALOMEDS::SObject_var aResultSO =
992 theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
993 aGeomObj, qPrintable( aName ) );
994 if ( aResultSO->_is_nil() ) {
995 aGeomObj = GEOM::GEOM_Object::_nil();
999 return aGeomObj._retn();