Salome HOME
Update mail address
[modules/geom.git] / src / NMTTools / NMTTools_CommonBlockAPI.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File:        NMTTools_CommonBlockAPI.cxx
21 // Created:     Mon Dec 15 11:38:04 2003
22 // Author:      Peter KURNEV
23 //              <pkv@irinox>
24
25
26 #include <NMTTools_CommonBlockAPI.ixx>
27
28 #include <BOPTools_PaveBlock.hxx>
29 #include <BOPTools_ListOfPaveBlock.hxx>
30 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
31
32 #include <NMTTools_CommonBlock.hxx>
33 #include <NMTTools_ListOfCommonBlock.hxx>
34 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
35
36 //=======================================================================
37 // function:  NMTTools_CommonBlockAPI::NMTTools_CommonBlockAPI
38 // purpose: 
39 //=======================================================================
40   NMTTools_CommonBlockAPI::NMTTools_CommonBlockAPI (const NMTTools_ListOfCommonBlock& aLCB)
41 {
42   myListOfCommonBlock=(void *)&aLCB;
43 }
44 //=======================================================================
45 // function:  List
46 // purpose: 
47 //=======================================================================
48   const NMTTools_ListOfCommonBlock& NMTTools_CommonBlockAPI::List () const
49 {
50   NMTTools_ListOfCommonBlock* pListOfCommonBlock=(NMTTools_ListOfCommonBlock*)myListOfCommonBlock;
51   return *pListOfCommonBlock;
52 }
53 //=======================================================================
54 // function:  CommonPaveBlocks
55 // purpose:   get all CommonPaveBlocks
56 //=======================================================================
57   const BOPTools_ListOfPaveBlock& NMTTools_CommonBlockAPI::CommonPaveBlocks(const Standard_Integer anE) const
58 {
59   Standard_Integer anECurrent;
60   BOPTools_ListIteratorOfListOfPaveBlock anItPB;
61   //
62   BOPTools_ListOfPaveBlock* pmyListOfPaveBlock=(BOPTools_ListOfPaveBlock*) &myListOfPaveBlock;
63   pmyListOfPaveBlock->Clear();
64
65   NMTTools_ListOfCommonBlock* pListOfCommonBlock=(NMTTools_ListOfCommonBlock*)myListOfCommonBlock;
66
67   NMTTools_ListIteratorOfListOfCommonBlock anIt(*pListOfCommonBlock);
68   for (; anIt.More(); anIt.Next()) {
69     const NMTTools_CommonBlock& aCB=anIt.Value();
70     //
71     const BOPTools_ListOfPaveBlock& aLPB=aCB.PaveBlocks();
72     anItPB.Initialize(aLPB);
73     for (; anItPB.More(); anItPB.Next()) {
74       const BOPTools_PaveBlock& aPB=anItPB.Value();
75       anECurrent=aPB.OriginalEdge();
76       if (anECurrent==anE) {
77         pmyListOfPaveBlock->Append(aPB);
78         break;
79       }
80     }
81   }
82   return myListOfPaveBlock;
83 }
84 //=======================================================================
85 // function:  IsCommonBlock
86 // purpose: 
87 //=======================================================================
88   Standard_Boolean NMTTools_CommonBlockAPI::IsCommonBlock(const BOPTools_PaveBlock& aPB) const
89 {
90   Standard_Integer anE;
91   //
92   anE=aPB.OriginalEdge();
93   //
94   CommonPaveBlocks(anE);
95   //
96   BOPTools_ListIteratorOfListOfPaveBlock anIt(myListOfPaveBlock);
97   for (; anIt.More(); anIt.Next()) {
98     const BOPTools_PaveBlock& aPB1=anIt.Value();
99     if (aPB1.IsEqual(aPB)) {
100       return Standard_True;
101     }
102   }
103   return Standard_False;
104 }
105
106 //=======================================================================
107 // function:  CommonBlock
108 // purpose: 
109 //=======================================================================
110   NMTTools_CommonBlock& NMTTools_CommonBlockAPI::CommonBlock(const BOPTools_PaveBlock& aPB)const
111 {
112   static NMTTools_CommonBlock aCBTMP;
113   //
114   NMTTools_ListIteratorOfListOfCommonBlock anItCB;
115   BOPTools_ListIteratorOfListOfPaveBlock anItPB;
116   //
117   NMTTools_ListOfCommonBlock* pLCB=(NMTTools_ListOfCommonBlock*)myListOfCommonBlock;
118   //
119   anItCB.Initialize(*pLCB);
120   for (; anItCB.More(); anItCB.Next()) {
121     NMTTools_CommonBlock& aCB=anItCB.Value();
122     //
123     const BOPTools_ListOfPaveBlock& aLPB=aCB.PaveBlocks();
124     anItPB.Initialize(aLPB);
125     for (; anItPB.More(); anItPB.Next()) {
126       const BOPTools_PaveBlock& aPBx=anItPB.Value();
127       if (aPBx.IsEqual(aPB)) {
128         return aCB;
129       }
130     }
131   }
132   return aCBTMP;
133 }