Salome HOME
093df705a393a052fb8027c449650a8143b106a7
[modules/geom.git] / src / GEOM_I / GEOM_IBlocksOperations_i.cc
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include <Standard_Stream.hxx>
23
24 #include "GEOM_IBlocksOperations_i.hh"
25
26 #include "utilities.h"
27 #include "OpUtil.hxx"
28 #include "Utils_ExceptHandlers.hxx"
29
30 #include "GEOM_Engine.hxx"
31 #include "GEOM_Object.hxx"
32
33 #include <TColStd_HSequenceOfTransient.hxx>
34 #include <TColStd_HArray1OfInteger.hxx>
35
36 //=============================================================================
37 /*!
38  *   constructor:
39  */
40 //=============================================================================
41 GEOM_IBlocksOperations_i::GEOM_IBlocksOperations_i (PortableServer::POA_ptr thePOA,
42                                                     GEOM::GEOM_Gen_ptr theEngine,
43                                                     ::GEOMImpl_IBlocksOperations* theImpl)
44 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
45 {
46   MESSAGE("GEOM_IBlocksOperations_i::GEOM_IBlocksOperations_i");
47 }
48
49 //=============================================================================
50 /*!
51  *  destructor
52  */
53 //=============================================================================
54 GEOM_IBlocksOperations_i::~GEOM_IBlocksOperations_i()
55 {
56   MESSAGE("GEOM_IBlocksOperations_i::~GEOM_IBlocksOperations_i");
57 }
58
59
60 //=============================================================================
61 /*!
62  *  MakeQuad
63  */
64 //=============================================================================
65 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeQuad
66                (GEOM::GEOM_Object_ptr theEdge1, GEOM::GEOM_Object_ptr theEdge2,
67                 GEOM::GEOM_Object_ptr theEdge3, GEOM::GEOM_Object_ptr theEdge4)
68 {
69   GEOM::GEOM_Object_var aGEOMObject;
70
71   //Set a not done flag
72   GetOperations()->SetNotDone();
73
74   if (theEdge1 == NULL || theEdge2 == NULL ||
75       theEdge3 == NULL || theEdge4 == NULL) return aGEOMObject._retn();
76
77   //Get the reference edges
78   Handle(GEOM_Object) anEdge1 = GetOperations()->GetEngine()->GetObject
79     (theEdge1->GetStudyID(), theEdge1->GetEntry());
80   Handle(GEOM_Object) anEdge2 = GetOperations()->GetEngine()->GetObject
81     (theEdge2->GetStudyID(), theEdge2->GetEntry());
82   Handle(GEOM_Object) anEdge3 = GetOperations()->GetEngine()->GetObject
83     (theEdge3->GetStudyID(), theEdge3->GetEntry());
84   Handle(GEOM_Object) anEdge4 = GetOperations()->GetEngine()->GetObject
85     (theEdge4->GetStudyID(), theEdge4->GetEntry());
86
87   if (anEdge1.IsNull() || anEdge2.IsNull() ||
88       anEdge3.IsNull() || anEdge4.IsNull()) return aGEOMObject._retn();
89
90   //Create the Face
91   Handle(GEOM_Object) anObject =
92     GetOperations()->MakeQuad(anEdge1, anEdge2, anEdge3, anEdge4);
93   if (!GetOperations()->IsDone() || anObject.IsNull())
94     return aGEOMObject._retn();
95
96   return GetObject(anObject);
97 }
98
99 //=============================================================================
100 /*!
101  *  MakeQuad2Edges
102  */
103 //=============================================================================
104 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeQuad2Edges
105                (GEOM::GEOM_Object_ptr theEdge1, GEOM::GEOM_Object_ptr theEdge2)
106 {
107   GEOM::GEOM_Object_var aGEOMObject;
108
109   //Set a not done flag
110   GetOperations()->SetNotDone();
111
112   if (theEdge1 == NULL || theEdge2 == NULL) return aGEOMObject._retn();
113
114   //Get the reference edges
115   Handle(GEOM_Object) anEdge1 = GetOperations()->GetEngine()->GetObject
116     (theEdge1->GetStudyID(), theEdge1->GetEntry());
117   Handle(GEOM_Object) anEdge2 = GetOperations()->GetEngine()->GetObject
118     (theEdge2->GetStudyID(), theEdge2->GetEntry());
119
120   if (anEdge1.IsNull() || anEdge2.IsNull()) return aGEOMObject._retn();
121
122   //Create the Face
123   Handle(GEOM_Object) anObject =
124     GetOperations()->MakeQuad2Edges(anEdge1, anEdge2);
125   if (!GetOperations()->IsDone() || anObject.IsNull())
126     return aGEOMObject._retn();
127
128   return GetObject(anObject);
129 }
130
131 //=============================================================================
132 /*!
133  *  MakeQuad4Vertices
134  */
135 //=============================================================================
136 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeQuad4Vertices
137                       (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2,
138                        GEOM::GEOM_Object_ptr thePnt3, GEOM::GEOM_Object_ptr thePnt4)
139 {
140   GEOM::GEOM_Object_var aGEOMObject;
141
142   //Set a not done flag
143   GetOperations()->SetNotDone();
144
145   if (thePnt1 == NULL || thePnt2 == NULL ||
146       thePnt3 == NULL || thePnt4 == NULL) return aGEOMObject._retn();
147
148   //Get the reference points
149   Handle(GEOM_Object) aPnt1 = GetOperations()->GetEngine()->GetObject
150     (thePnt1->GetStudyID(), thePnt1->GetEntry());
151   Handle(GEOM_Object) aPnt2 = GetOperations()->GetEngine()->GetObject
152     (thePnt2->GetStudyID(), thePnt2->GetEntry());
153   Handle(GEOM_Object) aPnt3 = GetOperations()->GetEngine()->GetObject
154     (thePnt3->GetStudyID(), thePnt3->GetEntry());
155   Handle(GEOM_Object) aPnt4 = GetOperations()->GetEngine()->GetObject
156     (thePnt4->GetStudyID(), thePnt4->GetEntry());
157
158   if (aPnt1.IsNull() || aPnt2.IsNull() ||
159       aPnt3.IsNull() || aPnt4.IsNull()) return aGEOMObject._retn();
160
161   //Create the Face
162   Handle(GEOM_Object) anObject =
163     GetOperations()->MakeQuad4Vertices(aPnt1, aPnt2, aPnt3, aPnt4);
164   if (!GetOperations()->IsDone() || anObject.IsNull())
165     return aGEOMObject._retn();
166
167   return GetObject(anObject);
168 }
169
170 //=============================================================================
171 /*!
172  *  MakeHexa
173  */
174 //=============================================================================
175 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeHexa
176                (GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theFace2,
177                 GEOM::GEOM_Object_ptr theFace3, GEOM::GEOM_Object_ptr theFace4,
178                 GEOM::GEOM_Object_ptr theFace5, GEOM::GEOM_Object_ptr theFace6)
179 {
180   GEOM::GEOM_Object_var aGEOMObject;
181
182   //Set a not done flag
183   GetOperations()->SetNotDone();
184
185   if (theFace1 == NULL || theFace2 == NULL ||
186       theFace3 == NULL || theFace4 == NULL ||
187       theFace5 == NULL || theFace6 == NULL) return aGEOMObject._retn();
188
189   //Get the reference Faces
190   Handle(GEOM_Object) anFace1 = GetOperations()->GetEngine()->GetObject
191     (theFace1->GetStudyID(), theFace1->GetEntry());
192   Handle(GEOM_Object) anFace2 = GetOperations()->GetEngine()->GetObject
193     (theFace2->GetStudyID(), theFace2->GetEntry());
194   Handle(GEOM_Object) anFace3 = GetOperations()->GetEngine()->GetObject
195     (theFace3->GetStudyID(), theFace3->GetEntry());
196   Handle(GEOM_Object) anFace4 = GetOperations()->GetEngine()->GetObject
197     (theFace4->GetStudyID(), theFace4->GetEntry());
198   Handle(GEOM_Object) anFace5 = GetOperations()->GetEngine()->GetObject
199     (theFace5->GetStudyID(), theFace5->GetEntry());
200   Handle(GEOM_Object) anFace6 = GetOperations()->GetEngine()->GetObject
201     (theFace6->GetStudyID(), theFace6->GetEntry());
202
203   if (anFace1.IsNull() || anFace2.IsNull() ||
204       anFace3.IsNull() || anFace4.IsNull() ||
205       anFace5.IsNull() || anFace6.IsNull()) return aGEOMObject._retn();
206
207   //Create the Face
208   Handle(GEOM_Object) anObject = GetOperations()->MakeHexa
209     (anFace1, anFace2, anFace3, anFace4, anFace5, anFace6);
210   if (!GetOperations()->IsDone() || anObject.IsNull())
211     return aGEOMObject._retn();
212
213   return GetObject(anObject);
214 }
215
216 //=============================================================================
217 /*!
218  *  MakeHexa2Faces
219  */
220 //=============================================================================
221 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeHexa2Faces
222                (GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theFace2)
223 {
224   GEOM::GEOM_Object_var aGEOMObject;
225
226   //Set a not done flag
227   GetOperations()->SetNotDone();
228
229   if (theFace1 == NULL || theFace2 == NULL) return aGEOMObject._retn();
230
231   //Get the reference Faces
232   Handle(GEOM_Object) anFace1 = GetOperations()->GetEngine()->GetObject
233     (theFace1->GetStudyID(), theFace1->GetEntry());
234   Handle(GEOM_Object) anFace2 = GetOperations()->GetEngine()->GetObject
235     (theFace2->GetStudyID(), theFace2->GetEntry());
236
237   if (anFace1.IsNull() || anFace2.IsNull()) return aGEOMObject._retn();
238
239   //Create the Face
240   Handle(GEOM_Object) anObject =
241     GetOperations()->MakeHexa2Faces(anFace1, anFace2);
242   if (!GetOperations()->IsDone() || anObject.IsNull())
243     return aGEOMObject._retn();
244
245   return GetObject(anObject);
246 }
247
248 //=============================================================================
249 /*!
250  *  MakeBlockCompound
251  */
252 //=============================================================================
253 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeBlockCompound
254                                             (GEOM::GEOM_Object_ptr theCompound)
255 {
256   GEOM::GEOM_Object_var aGEOMObject;
257
258   //Set a not done flag
259   GetOperations()->SetNotDone();
260
261   if (theCompound == NULL) return aGEOMObject._retn();
262
263   //Get the reference Compound
264   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
265     (theCompound->GetStudyID(), theCompound->GetEntry());
266
267   if (aCompound.IsNull()) return aGEOMObject._retn();
268
269   //Create the Blocks Compound
270   Handle(GEOM_Object) anObject =
271     GetOperations()->MakeBlockCompound(aCompound);
272   if (!GetOperations()->IsDone() || anObject.IsNull())
273     return aGEOMObject._retn();
274
275   return GetObject(anObject);
276 }
277
278 //=============================================================================
279 /*!
280  *  GetPoint
281  */
282 //=============================================================================
283 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetPoint (GEOM::GEOM_Object_ptr theShape,
284                                                           const CORBA::Double   theX,
285                                                           const CORBA::Double   theY,
286                                                           const CORBA::Double   theZ,
287                                                           const CORBA::Double   theEpsilon)
288 {
289   GEOM::GEOM_Object_var aGEOMObject;
290
291   //Set a not done flag
292   GetOperations()->SetNotDone();
293
294   if (theShape == NULL) return aGEOMObject._retn();
295
296   //Get the reference Objects
297   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
298     (theShape->GetStudyID(), theShape->GetEntry());
299
300   if (aShape.IsNull()) return aGEOMObject._retn();
301
302   //Create the Point
303   Handle(GEOM_Object) anObject =
304     GetOperations()->GetPoint(aShape, theX, theY, theZ, theEpsilon);
305   if (!GetOperations()->IsDone() || anObject.IsNull())
306     return aGEOMObject._retn();
307
308   return GetObject(anObject);
309 }
310
311 //=============================================================================
312 /*!
313  *  GetEdge
314  */
315 //=============================================================================
316 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetEdge (GEOM::GEOM_Object_ptr theShape,
317                                                          GEOM::GEOM_Object_ptr thePoint1,
318                                                          GEOM::GEOM_Object_ptr thePoint2)
319 {
320   GEOM::GEOM_Object_var aGEOMObject;
321
322   //Set a not done flag
323   GetOperations()->SetNotDone();
324
325   if (theShape == NULL ||
326       thePoint1 == NULL || thePoint2 == NULL) return aGEOMObject._retn();
327
328   //Get the reference Objects
329   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
330     (theShape->GetStudyID(), theShape->GetEntry());
331   Handle(GEOM_Object) aPoint1 = GetOperations()->GetEngine()->GetObject
332     (thePoint1->GetStudyID(), thePoint1->GetEntry());
333   Handle(GEOM_Object) aPoint2 = GetOperations()->GetEngine()->GetObject
334     (thePoint2->GetStudyID(), thePoint2->GetEntry());
335
336   if (aShape.IsNull() ||
337       aPoint1.IsNull() || aPoint2.IsNull()) return aGEOMObject._retn();
338
339   //Create the Point
340   Handle(GEOM_Object) anObject =
341     GetOperations()->GetEdge(aShape, aPoint1, aPoint2);
342   if (!GetOperations()->IsDone() || anObject.IsNull())
343     return aGEOMObject._retn();
344
345   return GetObject(anObject);
346 }
347
348 //=============================================================================
349 /*!
350  *  GetEdgeNearPoint
351  */
352 //=============================================================================
353 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetEdgeNearPoint (GEOM::GEOM_Object_ptr theShape,
354                                                                   GEOM::GEOM_Object_ptr thePoint)
355 {
356   GEOM::GEOM_Object_var aGEOMObject;
357
358   //Set a not done flag
359   GetOperations()->SetNotDone();
360
361   if (theShape == NULL || thePoint == NULL) return aGEOMObject._retn();
362
363   //Get the reference Objects
364   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
365     (theShape->GetStudyID(), theShape->GetEntry());
366   Handle(GEOM_Object) aPoint = GetOperations()->GetEngine()->GetObject
367     (thePoint->GetStudyID(), thePoint->GetEntry());
368
369   if (aShape.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
370
371   //Create the Edge
372   Handle(GEOM_Object) anObject =
373     GetOperations()->GetEdgeNearPoint(aShape, aPoint);
374   if (!GetOperations()->IsDone() || anObject.IsNull())
375     return aGEOMObject._retn();
376
377   return GetObject(anObject);
378 }
379
380 //=============================================================================
381 /*!
382  *  GetFaceByPoints
383  */
384 //=============================================================================
385 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceByPoints
386                                               (GEOM::GEOM_Object_ptr theShape,
387                                                GEOM::GEOM_Object_ptr thePoint1,
388                                                GEOM::GEOM_Object_ptr thePoint2,
389                                                GEOM::GEOM_Object_ptr thePoint3,
390                                                GEOM::GEOM_Object_ptr thePoint4)
391 {
392   GEOM::GEOM_Object_var aGEOMObject;
393
394   //Set a not done flag
395   GetOperations()->SetNotDone();
396
397   if (theShape == NULL ||
398       thePoint1 == NULL || thePoint2 == NULL ||
399       thePoint3 == NULL || thePoint4 == NULL) return aGEOMObject._retn();
400
401   //Get the reference Objects
402   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
403     (theShape->GetStudyID(), theShape->GetEntry());
404   Handle(GEOM_Object) aPoint1 = GetOperations()->GetEngine()->GetObject
405     (thePoint1->GetStudyID(), thePoint1->GetEntry());
406   Handle(GEOM_Object) aPoint2 = GetOperations()->GetEngine()->GetObject
407     (thePoint2->GetStudyID(), thePoint2->GetEntry());
408   Handle(GEOM_Object) aPoint3 = GetOperations()->GetEngine()->GetObject
409     (thePoint3->GetStudyID(), thePoint3->GetEntry());
410   Handle(GEOM_Object) aPoint4 = GetOperations()->GetEngine()->GetObject
411     (thePoint4->GetStudyID(), thePoint4->GetEntry());
412
413   if (aShape.IsNull() ||
414       aPoint1.IsNull() || aPoint2.IsNull() ||
415       aPoint3.IsNull() || aPoint4.IsNull()) return aGEOMObject._retn();
416
417   //Create the Face
418   Handle(GEOM_Object) anObject =
419     GetOperations()->GetFaceByPoints(aShape, aPoint1, aPoint2, aPoint3, aPoint4);
420   if (!GetOperations()->IsDone() || anObject.IsNull())
421     return aGEOMObject._retn();
422
423   return GetObject(anObject);
424 }
425
426 //=============================================================================
427 /*!
428  *  GetFaceByEdges
429  */
430 //=============================================================================
431 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceByEdges
432                                                (GEOM::GEOM_Object_ptr theShape,
433                                                 GEOM::GEOM_Object_ptr theEdge1,
434                                                 GEOM::GEOM_Object_ptr theEdge2)
435 {
436   GEOM::GEOM_Object_var aGEOMObject;
437
438   //Set a not done flag
439   GetOperations()->SetNotDone();
440
441   if (theShape == NULL ||
442       theEdge1 == NULL || theEdge2 == NULL) return aGEOMObject._retn();
443
444   //Get the reference Objects
445   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
446     (theShape->GetStudyID(), theShape->GetEntry());
447   Handle(GEOM_Object) anEdge1 = GetOperations()->GetEngine()->GetObject
448     (theEdge1->GetStudyID(), theEdge1->GetEntry());
449   Handle(GEOM_Object) anEdge2 = GetOperations()->GetEngine()->GetObject
450     (theEdge2->GetStudyID(), theEdge2->GetEntry());
451
452   if (aShape.IsNull() ||
453       anEdge1.IsNull() || anEdge2.IsNull()) return aGEOMObject._retn();
454
455   //Create the Face
456   Handle(GEOM_Object) anObject =
457     GetOperations()->GetFaceByEdges(aShape, anEdge1, anEdge2);
458   if (!GetOperations()->IsDone() || anObject.IsNull())
459     return aGEOMObject._retn();
460
461   return GetObject(anObject);
462 }
463
464 //=============================================================================
465 /*!
466  *  GetOppositeFace
467  */
468 //=============================================================================
469 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetOppositeFace (GEOM::GEOM_Object_ptr theShape,
470                                                                  GEOM::GEOM_Object_ptr theFace)
471 {
472   GEOM::GEOM_Object_var aGEOMObject;
473
474   //Set a not done flag
475   GetOperations()->SetNotDone();
476
477   if (theShape == NULL || theFace == NULL) return aGEOMObject._retn();
478
479   //Get the reference Objects
480   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
481     (theShape->GetStudyID(), theShape->GetEntry());
482   Handle(GEOM_Object) aFace = GetOperations()->GetEngine()->GetObject
483     (theFace->GetStudyID(), theFace->GetEntry());
484
485   if (aShape.IsNull() || aFace.IsNull()) return aGEOMObject._retn();
486
487   //Create the Face
488   Handle(GEOM_Object) anObject =
489     GetOperations()->GetOppositeFace(aShape, aFace);
490   if (!GetOperations()->IsDone() || anObject.IsNull())
491     return aGEOMObject._retn();
492
493   return GetObject(anObject);
494 }
495
496 //=============================================================================
497 /*!
498  *  GetFaceNearPoint
499  */
500 //=============================================================================
501 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceNearPoint (GEOM::GEOM_Object_ptr theShape,
502                                                                   GEOM::GEOM_Object_ptr thePoint)
503 {
504   GEOM::GEOM_Object_var aGEOMObject;
505
506   //Set a not done flag
507   GetOperations()->SetNotDone();
508
509   if (theShape == NULL || thePoint == NULL) return aGEOMObject._retn();
510
511   //Get the reference Objects
512   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
513     (theShape->GetStudyID(), theShape->GetEntry());
514   Handle(GEOM_Object) aPoint = GetOperations()->GetEngine()->GetObject
515     (thePoint->GetStudyID(), thePoint->GetEntry());
516
517   if (aShape.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
518
519   //Create the Face
520   Handle(GEOM_Object) anObject =
521     GetOperations()->GetFaceNearPoint(aShape, aPoint);
522   if (!GetOperations()->IsDone() || anObject.IsNull())
523     return aGEOMObject._retn();
524
525   return GetObject(anObject);
526 }
527
528 //=============================================================================
529 /*!
530  *  GetFaceByNormale
531  */
532 //=============================================================================
533 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceByNormale (GEOM::GEOM_Object_ptr theShape,
534                                                                   GEOM::GEOM_Object_ptr theVector)
535 {
536   GEOM::GEOM_Object_var aGEOMObject;
537
538   //Set a not done flag
539   GetOperations()->SetNotDone();
540
541   if (theShape == NULL || theVector == NULL) return aGEOMObject._retn();
542
543   //Get the reference Objects
544   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
545     (theShape->GetStudyID(), theShape->GetEntry());
546   Handle(GEOM_Object) aVector = GetOperations()->GetEngine()->GetObject
547     (theVector->GetStudyID(), theVector->GetEntry());
548
549   if (aShape.IsNull() || aVector.IsNull()) return aGEOMObject._retn();
550
551   //Create the Face
552   Handle(GEOM_Object) anObject =
553     GetOperations()->GetFaceByNormale(aShape, aVector);
554   if (!GetOperations()->IsDone() || anObject.IsNull())
555     return aGEOMObject._retn();
556
557   return GetObject(anObject);
558 }
559
560 //=============================================================================
561 /*!
562  *  ExplodeCompoundOfBlocks
563  */
564 //=============================================================================
565 GEOM::ListOfGO* GEOM_IBlocksOperations_i::ExplodeCompoundOfBlocks
566                                           (GEOM::GEOM_Object_ptr theCompound,
567                                            const CORBA::Long     theMinNbFaces,
568                                            const CORBA::Long     theMaxNbFaces)
569 {
570   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
571
572   //Set a not done flag
573   GetOperations()->SetNotDone();
574
575   if (theCompound == NULL) return aSeq._retn();
576
577   //Get the reference Compound
578   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
579     (theCompound->GetStudyID(), theCompound->GetEntry());
580
581   if (aCompound.IsNull()) return aSeq._retn();
582
583   //Explode
584   Handle(TColStd_HSequenceOfTransient) aHSeq =
585     GetOperations()->ExplodeCompoundOfBlocks(aCompound, theMinNbFaces, theMaxNbFaces);
586   if (!GetOperations()->IsDone() || aHSeq.IsNull())
587     return aSeq._retn();
588
589   Standard_Integer aLength = aHSeq->Length();
590   aSeq->length(aLength);
591   for (Standard_Integer i = 1; i <= aLength; i++)
592     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
593
594   return aSeq._retn();
595 }
596
597 //=============================================================================
598 /*!
599  *  IsCompoundOfBlocks
600  */
601 //=============================================================================
602 CORBA::Boolean GEOM_IBlocksOperations_i::IsCompoundOfBlocks
603                                           (GEOM::GEOM_Object_ptr theCompound,
604                                            const CORBA::Long     theMinNbFaces,
605                                            const CORBA::Long     theMaxNbFaces,
606                                            CORBA::Long&          theNbBlocks)
607 {
608   theNbBlocks = 0;
609   CORBA::Boolean isComp = false;
610
611   //Set a not done flag
612   GetOperations()->SetNotDone();
613
614   if (theCompound == NULL) return isComp;
615
616   //Get the reference Compound
617   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
618     (theCompound->GetStudyID(), theCompound->GetEntry());
619
620   if (aCompound.IsNull()) return isComp;
621
622   //Check
623   Standard_Integer nbBlocks = 0;
624   isComp = GetOperations()->IsCompoundOfBlocks(aCompound,
625                                                theMinNbFaces,
626                                                theMaxNbFaces,
627                                                nbBlocks);
628   if (!GetOperations()->IsDone())
629     return isComp;
630
631   theNbBlocks = nbBlocks;
632   return isComp;
633 }
634
635 //=============================================================================
636 /*!
637  *  CheckCompoundOfBlocks
638  */
639 //=============================================================================
640 CORBA::Boolean GEOM_IBlocksOperations_i::CheckCompoundOfBlocks
641                                           (GEOM::GEOM_Object_ptr theCompound,
642                                            GEOM::GEOM_IBlocksOperations::BCErrors_out theErrors)
643 {
644   CORBA::Boolean isComp = false;
645
646   //Set a not done flag
647   GetOperations()->SetNotDone();
648
649   if (theCompound == NULL) return isComp;
650
651   //Get the reference Compound
652   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
653     (theCompound->GetStudyID(), theCompound->GetEntry());
654
655   if (aCompound.IsNull()) return isComp;
656
657   //Check
658   list<GEOMImpl_IBlocksOperations::BCError> errList;
659   isComp = GetOperations()->CheckCompoundOfBlocks(aCompound, errList);
660   if (!GetOperations()->IsDone())
661     return isComp;
662
663   const int nbErr = errList.size();
664   GEOM::GEOM_IBlocksOperations::BCErrors_var anErrArray =
665     new GEOM::GEOM_IBlocksOperations::BCErrors();
666   anErrArray->length(nbErr);
667
668   // fill the local CORBA array with values from lists
669   list<GEOMImpl_IBlocksOperations::BCError>::iterator errIt = errList.begin();
670   int i = 0;
671   for (; errIt != errList.end(); i++, errIt++) {
672     GEOM::GEOM_IBlocksOperations::BCError_var anError =
673       new GEOM::GEOM_IBlocksOperations::BCError();
674
675     GEOMImpl_IBlocksOperations::BCError errStruct = *errIt;
676
677     switch (errStruct.error) {
678     case GEOMImpl_IBlocksOperations::NOT_BLOCK:
679       anError->error = GEOM::GEOM_IBlocksOperations::NOT_BLOCK;
680       break;
681     case GEOMImpl_IBlocksOperations::EXTRA_EDGE:
682       anError->error = GEOM::GEOM_IBlocksOperations::EXTRA_EDGE;
683       break;
684     case GEOMImpl_IBlocksOperations::INVALID_CONNECTION:
685       anError->error = GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION;
686       break;
687     case GEOMImpl_IBlocksOperations::NOT_CONNECTED:
688       anError->error = GEOM::GEOM_IBlocksOperations::NOT_CONNECTED;
689       break;
690     case GEOMImpl_IBlocksOperations::NOT_GLUED:
691       anError->error = GEOM::GEOM_IBlocksOperations::NOT_GLUED;
692       break;
693     default:
694       break;
695     }
696
697     list<int> sshList = errStruct.incriminated;
698     GEOM::ListOfLong_var anIncrims = new GEOM::ListOfLong();
699     anIncrims->length(sshList.size());
700
701     list<int>::iterator sshIt = sshList.begin();
702     int jj = 0;
703     for (; sshIt != sshList.end(); jj++, sshIt++) {
704       anIncrims[jj] = *sshIt;
705     }
706
707     anError->incriminated = anIncrims;
708
709     anErrArray[i] = anError;
710   }
711
712   // initialize out-parameter with local array
713   theErrors = anErrArray._retn();
714
715   return isComp;
716 }
717
718 //=============================================================================
719 /*!
720  *  PrintBCErrors
721  */
722 //=============================================================================
723 char* GEOM_IBlocksOperations_i::PrintBCErrors
724                       (GEOM::GEOM_Object_ptr theCompound,
725                        const GEOM::GEOM_IBlocksOperations::BCErrors& theErrors)
726 {
727   //Get the reference Compound
728   if (theCompound == NULL) return NULL;
729   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
730     (theCompound->GetStudyID(), theCompound->GetEntry());
731   if (aCompound.IsNull()) return NULL;
732
733   // Convert the errors sequence
734   list<GEOMImpl_IBlocksOperations::BCError> anErrors;
735   int nbErr = theErrors.length();
736   int ie = 0;
737   for (; ie < nbErr; ie++) {
738     const GEOM::GEOM_IBlocksOperations::BCError err = theErrors[ie];
739     const GEOM::GEOM_IBlocksOperations::BCErrorType typ = err.error;
740     const GEOM::ListOfLong incrims = err.incriminated;
741
742     GEOMImpl_IBlocksOperations::BCError errStruct;
743     switch (typ) {
744     case GEOM::GEOM_IBlocksOperations::NOT_BLOCK:
745       errStruct.error = GEOMImpl_IBlocksOperations::NOT_BLOCK;
746       break;
747     case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE:
748       errStruct.error = GEOMImpl_IBlocksOperations::EXTRA_EDGE;
749       break;
750     case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION:
751       errStruct.error = GEOMImpl_IBlocksOperations::INVALID_CONNECTION;
752       break;
753     case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED:
754       errStruct.error = GEOMImpl_IBlocksOperations::NOT_CONNECTED;
755       break;
756     case GEOM::GEOM_IBlocksOperations::NOT_GLUED:
757       errStruct.error = GEOMImpl_IBlocksOperations::NOT_GLUED;
758       break;
759     default:
760       break;
761     }
762
763     int ii = 0;
764     int aLen = incrims.length();
765     for (; ii < aLen; ii++) {
766       errStruct.incriminated.push_back(incrims[ii]);
767     }
768
769     anErrors.push_back(errStruct);
770   }
771
772   TCollection_AsciiString aDescr = GetOperations()->PrintBCErrors(aCompound, anErrors);
773   return CORBA::string_dup(aDescr.ToCString());    
774 }
775
776 //=============================================================================
777 /*!
778  *  RemoveExtraEdges
779  */
780 //=============================================================================
781 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::RemoveExtraEdges (GEOM::GEOM_Object_ptr theShape)
782 {
783   GEOM::GEOM_Object_var aGEOMObject;
784
785   //Set a not done flag
786   GetOperations()->SetNotDone();
787
788   if (theShape == NULL) return aGEOMObject._retn();
789
790   //Get the reference Objects
791   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
792     (theShape->GetStudyID(), theShape->GetEntry());
793
794   if (aShape.IsNull()) return aGEOMObject._retn();
795
796   //Get the result
797   Handle(GEOM_Object) anObject =
798     GetOperations()->RemoveExtraEdges(aShape);
799   if (!GetOperations()->IsDone() || anObject.IsNull())
800     return aGEOMObject._retn();
801
802   return GetObject(anObject);
803 }
804
805 //=============================================================================
806 /*!
807  *  CheckAndImprove
808  */
809 //=============================================================================
810 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::CheckAndImprove (GEOM::GEOM_Object_ptr theCompound)
811 {
812   GEOM::GEOM_Object_var aGEOMObject;
813
814   //Set a not done flag
815   GetOperations()->SetNotDone();
816
817   if (theCompound == NULL) return aGEOMObject._retn();
818
819   //Get the reference Objects
820   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
821     (theCompound->GetStudyID(), theCompound->GetEntry());
822
823   if (aCompound.IsNull()) return aGEOMObject._retn();
824
825   //Get the result
826   Handle(GEOM_Object) anObject =
827     GetOperations()->CheckAndImprove(aCompound);
828   if (!GetOperations()->IsDone() || anObject.IsNull())
829     return aGEOMObject._retn();
830
831   return GetObject(anObject);
832 }
833
834 //=============================================================================
835 /*!
836  *  GetBlockNearPoint
837  */
838 //=============================================================================
839 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetBlockNearPoint (GEOM::GEOM_Object_ptr theCompound,
840                                                                    GEOM::GEOM_Object_ptr thePoint)
841 {
842   GEOM::GEOM_Object_var aGEOMObject;
843
844   //Set a not done flag
845   GetOperations()->SetNotDone();
846
847   if (theCompound == NULL || thePoint == NULL) return aGEOMObject._retn();
848
849   //Get the reference Objects
850   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
851     (theCompound->GetStudyID(), theCompound->GetEntry());
852   Handle(GEOM_Object) aPoint = GetOperations()->GetEngine()->GetObject
853     (thePoint->GetStudyID(), thePoint->GetEntry());
854
855   if (aCompound.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
856
857   //Get the block
858   Handle(GEOM_Object) anObject =
859     GetOperations()->GetBlockNearPoint(aCompound, aPoint);
860   if (!GetOperations()->IsDone() || anObject.IsNull())
861     return aGEOMObject._retn();
862
863   return GetObject(anObject);
864 }
865
866 //=============================================================================
867 /*!
868  *  GetBlockByParts
869  */
870 //=============================================================================
871 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetBlockByParts (GEOM::GEOM_Object_ptr theCompound,
872                                                                  const GEOM::ListOfGO& theParts)
873 {
874   GEOM::GEOM_Object_var aGEOMObject;
875
876   //Set a not done flag
877   GetOperations()->SetNotDone();
878
879   if (theCompound == NULL) return aGEOMObject._retn();
880
881   //Get the reference Compound
882   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
883     (theCompound->GetStudyID(), theCompound->GetEntry());
884
885   if (aCompound.IsNull()) return aGEOMObject._retn();
886
887   //Get the parts
888   int ind, aLen;
889   Handle(TColStd_HSequenceOfTransient) aParts = new TColStd_HSequenceOfTransient;
890
891   aLen = theParts.length();
892   for (ind = 0; ind < aLen; ind++) {
893     if (theParts[ind] == NULL) return aGEOMObject._retn();
894     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
895       (theParts[ind]->GetStudyID(), theParts[ind]->GetEntry());
896     if (aSh.IsNull()) return aGEOMObject._retn();
897     aParts->Append(aSh);
898   }
899
900   //Get the Block
901   Handle(GEOM_Object) anObject =
902     GetOperations()->GetBlockByParts(aCompound, aParts);
903   if (!GetOperations()->IsDone() || anObject.IsNull())
904     return aGEOMObject._retn();
905
906   return GetObject(anObject);
907 }
908
909 //=============================================================================
910 /*!
911  *  GetBlocksByParts
912  */
913 //=============================================================================
914 GEOM::ListOfGO* GEOM_IBlocksOperations_i::GetBlocksByParts (GEOM::GEOM_Object_ptr theCompound,
915                                                             const GEOM::ListOfGO& theParts)
916 {
917   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
918
919   //Set a not done flag
920   GetOperations()->SetNotDone();
921
922   if (theCompound == NULL) return aSeq._retn();
923
924   //Get the reference Compound
925   Handle(GEOM_Object) aCompound = GetOperations()->GetEngine()->GetObject
926     (theCompound->GetStudyID(), theCompound->GetEntry());
927
928   if (aCompound.IsNull()) return aSeq._retn();
929
930   //Get the parts
931   int ind, aLen;
932   Handle(TColStd_HSequenceOfTransient) aParts = new TColStd_HSequenceOfTransient;
933
934   aLen = theParts.length();
935   for (ind = 0; ind < aLen; ind++) {
936     if (theParts[ind] == NULL) return aSeq._retn();
937     Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
938       (theParts[ind]->GetStudyID(), theParts[ind]->GetEntry());
939     if (aSh.IsNull()) return aSeq._retn();
940     aParts->Append(aSh);
941   }
942
943   //Get the Block
944   Handle(TColStd_HSequenceOfTransient) aHSeq =
945     GetOperations()->GetBlocksByParts(aCompound, aParts);
946   if (!GetOperations()->IsDone() || aHSeq.IsNull())
947     return aSeq._retn();
948
949   Standard_Integer aLength = aHSeq->Length();
950   aSeq->length(aLength);
951   for (Standard_Integer i = 1; i <= aLength; i++)
952     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
953
954   return aSeq._retn();
955 }
956
957 //=============================================================================
958 /*!
959  *  MakeMultiTransformation1D
960  */
961 //=============================================================================
962 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeMultiTransformation1D
963                                               (GEOM::GEOM_Object_ptr theBlock,
964                                                const CORBA::Long     theDirFace1,
965                                                const CORBA::Long     theDirFace2,
966                                                const CORBA::Long     theNbTimes)
967 {
968   GEOM::GEOM_Object_var aGEOMObject;
969
970    //Set a not done flag
971   GetOperations()->SetNotDone();
972
973   if (theBlock == NULL) return aGEOMObject._retn();
974
975    //Get the object itself and the vector of translation
976    Handle(GEOM_Object) aBasicObject = GetOperations()->GetEngine()->GetObject
977      (theBlock->GetStudyID(), theBlock->GetEntry());
978
979    if (aBasicObject.IsNull()) return aGEOMObject._retn();
980
981    //Perform the transformation
982    Handle(GEOM_Object) anObject = GetOperations()->MakeMultiTransformation1D
983      (aBasicObject, theDirFace1, theDirFace2, theNbTimes);
984    if (!GetOperations()->IsDone() || anObject.IsNull())  return aGEOMObject._retn();
985
986    return GetObject(anObject);
987 }
988
989 //=============================================================================
990 /*!
991  *  MakeMultiTransformation2D
992  */
993 //=============================================================================
994 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeMultiTransformation2D
995                                            (GEOM::GEOM_Object_ptr theBlock,
996                                             const CORBA::Long     theDirFace1U,
997                                             const CORBA::Long     theDirFace2U,
998                                             const CORBA::Long     theNbTimesU,
999                                             const CORBA::Long     theDirFace1V,
1000                                             const CORBA::Long     theDirFace2V,
1001                                             const CORBA::Long     theNbTimesV)
1002 {
1003   GEOM::GEOM_Object_var aGEOMObject;
1004
1005   //Set a not done flag
1006   GetOperations()->SetNotDone();
1007
1008   if (theBlock == NULL) return aGEOMObject._retn();
1009
1010   //Get the object itself
1011   Handle(GEOM_Object) aBasicObject = GetOperations()->GetEngine()->GetObject
1012     (theBlock->GetStudyID(), theBlock->GetEntry());
1013
1014   if (aBasicObject.IsNull()) return aGEOMObject._retn();
1015
1016   //Perform the transformation
1017   Handle(GEOM_Object) anObject = GetOperations()->MakeMultiTransformation2D
1018     (aBasicObject,
1019      theDirFace1U, theDirFace2U, theNbTimesU,
1020      theDirFace1V, theDirFace2V, theNbTimesV);
1021   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
1022
1023   return GetObject(anObject);
1024 }
1025
1026 //=============================================================================
1027 /*!
1028  *  Propagate
1029  */
1030 //=============================================================================
1031 GEOM::ListOfGO* GEOM_IBlocksOperations_i::Propagate (GEOM::GEOM_Object_ptr theShape)
1032 {
1033   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1034
1035   //Set a not done flag
1036   GetOperations()->SetNotDone();
1037
1038   if (theShape == NULL) return aSeq._retn();
1039
1040   //Get the reference Shape
1041   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
1042     (theShape->GetStudyID(), theShape->GetEntry());
1043
1044   if (aShape.IsNull()) return aSeq._retn();
1045
1046   //Get the Propagation chains
1047   Handle(TColStd_HSequenceOfTransient) aHSeq =
1048     GetOperations()->Propagate(aShape);
1049   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1050     return aSeq._retn();
1051
1052   Standard_Integer aLength = aHSeq->Length();
1053   aSeq->length(aLength);
1054   for (Standard_Integer i = 1; i <= aLength; i++)
1055     aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i)));
1056
1057   return aSeq._retn();
1058 }