Salome HOME
817f328cbcf0c448ac12f913e489dcc82e9dcc77
[modules/geom.git] / src / NMTTools / NMTTools_CommonBlockAPI.cxx
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 // File:        NMTTools_CommonBlockAPI.cxx
23 // Created:     Mon Dec 15 11:38:04 2003
24 // Author:      Peter KURNEV
25 //              <pkv@irinox>
26 //
27 #include <NMTTools_CommonBlockAPI.ixx>
28
29 #include <BOPTools_PaveBlock.hxx>
30 #include <BOPTools_ListOfPaveBlock.hxx>
31 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
32
33 #include <NMTTools_CommonBlock.hxx>
34 #include <NMTTools_ListOfCommonBlock.hxx>
35 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
36
37 //=======================================================================
38 // function:  NMTTools_CommonBlockAPI::NMTTools_CommonBlockAPI
39 // purpose: 
40 //=======================================================================
41   NMTTools_CommonBlockAPI::NMTTools_CommonBlockAPI (const NMTTools_ListOfCommonBlock& aLCB)
42 {
43   myListOfCommonBlock=(void *)&aLCB;
44 }
45 //=======================================================================
46 // function:  List
47 // purpose: 
48 //=======================================================================
49   const NMTTools_ListOfCommonBlock& NMTTools_CommonBlockAPI::List () const
50 {
51   NMTTools_ListOfCommonBlock* pListOfCommonBlock=(NMTTools_ListOfCommonBlock*)myListOfCommonBlock;
52   return *pListOfCommonBlock;
53 }
54 //=======================================================================
55 // function:  CommonPaveBlocks
56 // purpose:   get all CommonPaveBlocks
57 //=======================================================================
58   const BOPTools_ListOfPaveBlock& NMTTools_CommonBlockAPI::CommonPaveBlocks(const Standard_Integer anE) const
59 {
60   Standard_Integer anECurrent;
61   BOPTools_ListIteratorOfListOfPaveBlock anItPB;
62   //
63   BOPTools_ListOfPaveBlock* pmyListOfPaveBlock=(BOPTools_ListOfPaveBlock*) &myListOfPaveBlock;
64   pmyListOfPaveBlock->Clear();
65
66   NMTTools_ListOfCommonBlock* pListOfCommonBlock=(NMTTools_ListOfCommonBlock*)myListOfCommonBlock;
67
68   NMTTools_ListIteratorOfListOfCommonBlock anIt(*pListOfCommonBlock);
69   for (; anIt.More(); anIt.Next()) {
70     const NMTTools_CommonBlock& aCB=anIt.Value();
71     //
72     const BOPTools_ListOfPaveBlock& aLPB=aCB.PaveBlocks();
73     anItPB.Initialize(aLPB);
74     for (; anItPB.More(); anItPB.Next()) {
75       const BOPTools_PaveBlock& aPB=anItPB.Value();
76       anECurrent=aPB.OriginalEdge();
77       if (anECurrent==anE) {
78         pmyListOfPaveBlock->Append(aPB);
79         break;
80       }
81     }
82   }
83   return myListOfPaveBlock;
84 }
85 //=======================================================================
86 // function:  IsCommonBlock
87 // purpose: 
88 //=======================================================================
89   Standard_Boolean NMTTools_CommonBlockAPI::IsCommonBlock(const BOPTools_PaveBlock& aPB) const
90 {
91   Standard_Integer anE;
92   //
93   anE=aPB.OriginalEdge();
94   //
95   CommonPaveBlocks(anE);
96   //
97   BOPTools_ListIteratorOfListOfPaveBlock anIt(myListOfPaveBlock);
98   for (; anIt.More(); anIt.Next()) {
99     const BOPTools_PaveBlock& aPB1=anIt.Value();
100     if (aPB1.IsEqual(aPB)) {
101       return Standard_True;
102     }
103   }
104   return Standard_False;
105 }
106
107 //=======================================================================
108 // function:  CommonBlock
109 // purpose: 
110 //=======================================================================
111   NMTTools_CommonBlock& NMTTools_CommonBlockAPI::CommonBlock(const BOPTools_PaveBlock& aPB)const
112 {
113   static NMTTools_CommonBlock aCBTMP;
114   //
115   NMTTools_ListIteratorOfListOfCommonBlock anItCB;
116   BOPTools_ListIteratorOfListOfPaveBlock anItPB;
117   //
118   NMTTools_ListOfCommonBlock* pLCB=(NMTTools_ListOfCommonBlock*)myListOfCommonBlock;
119   //
120   anItCB.Initialize(*pLCB);
121   for (; anItCB.More(); anItCB.Next()) {
122     NMTTools_CommonBlock& aCB=anItCB.Value();
123     //
124     const BOPTools_ListOfPaveBlock& aLPB=aCB.PaveBlocks();
125     anItPB.Initialize(aLPB);
126     for (; anItPB.More(); anItPB.Next()) {
127       const BOPTools_PaveBlock& aPBx=anItPB.Value();
128       if (aPBx.IsEqual(aPB)) {
129         return aCB;
130       }
131     }
132   }
133   return aCBTMP;
134 }