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