0023934: Compiler warnings in MS VC++ 10
[occt.git] / src / ShapeProcessAPI / ShapeProcessAPI_ApplySequence.cxx
1 // Created on: 1999-06-22
2 // Created by: data exchange team
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 #include <ShapeProcessAPI_ApplySequence.ixx>
24 #include <TCollection_AsciiString.hxx>
25 #include <TopoDS_Iterator.hxx>
26 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
27 #include <Message_Messenger.hxx>
28 #include <Message_Msg.hxx>
29 #include <Resource_Manager.hxx>
30 #include <ShapeProcess.hxx>
31 #include <ShapeProcess_OperLibrary.hxx>
32
33 //=======================================================================
34 //function : ShapeProcessAPI_ApplySequence
35 //purpose  : 
36 //=======================================================================
37
38 ShapeProcessAPI_ApplySequence::ShapeProcessAPI_ApplySequence(const Standard_CString rscName, 
39                                                              const Standard_CString seqName)
40 {
41
42   myContext = new ShapeProcess_ShapeContext(rscName);
43   myContext->SetDetalisation ( TopAbs_FACE );
44   TCollection_AsciiString str ( seqName );
45
46   // initialize operators
47   ShapeProcess_OperLibrary::Init ();
48   
49   mySeq = str;
50 }
51
52 //=======================================================================
53 //function : Context
54 //purpose  : 
55 //=======================================================================
56
57 Handle(ShapeProcess_ShapeContext)& ShapeProcessAPI_ApplySequence::Context()
58 {
59   return myContext;
60 }
61
62 //=======================================================================
63 //function : PrepareShape
64 //purpose  : 
65 //=======================================================================
66
67 TopoDS_Shape ShapeProcessAPI_ApplySequence::PrepareShape(const TopoDS_Shape& shape,
68                                                          const Standard_Boolean /*fillmap*/,
69                                                          const TopAbs_ShapeEnum /*until*/)
70 {
71   Handle(Resource_Manager) rsc = myContext->ResourceManager();
72   myContext->Init(shape);
73   
74   TCollection_AsciiString str(mySeq);
75   str += ".exec.op";
76   if ( rsc->Find ( str.ToCString() ) ) {
77     ShapeProcess::Perform ( myContext, mySeq.ToCString() );
78   }
79   
80   return myContext->Result();
81 }
82
83 //=======================================================================
84 //function : ClearMap
85 //purpose  : 
86 //=======================================================================
87
88  void ShapeProcessAPI_ApplySequence::ClearMap() 
89 {
90   //myContext->Map().Clear();
91 }
92
93 //=======================================================================
94 //function : Map
95 //purpose  : 
96 //=======================================================================
97
98 const TopTools_DataMapOfShapeShape& ShapeProcessAPI_ApplySequence::Map() const
99 {
100   return myContext->Map();
101 }
102
103 //=======================================================================
104 //function : PrintPreparationResult
105 //purpose  : 
106 //=======================================================================
107
108 void ShapeProcessAPI_ApplySequence::PrintPreparationResult () const
109 {
110   Standard_Integer SS = 0, SN = 0, FF = 0, FS = 0, FN = 0;
111   for (TopTools_DataMapIteratorOfDataMapOfShapeShape It (myContext->Map()); It.More(); It.Next()) {
112     TopoDS_Shape keyshape = It.Key(), valueshape = It.Value();
113     if (keyshape.ShapeType() == TopAbs_SHELL)
114       if (valueshape.IsNull()) SN++;
115       else SS++;
116     else if (keyshape.ShapeType() == TopAbs_FACE)
117       if (valueshape.IsNull()) FN++;
118       else if (valueshape.ShapeType() == TopAbs_SHELL) FS++;
119       else FF++;
120   }
121   
122   Handle(Message_Messenger) aMessenger = myContext->Messenger();
123
124   // mapping
125   Message_Msg EPMSG100 ("PrResult.Print.MSG100"); //Mapping:
126   aMessenger->Send (EPMSG100, Message_Info, Standard_True);
127   Message_Msg TPMSG50 ("PrResult.Print.MSG50"); //  Shells:
128   aMessenger->Send (TPMSG50, Message_Info, Standard_True);
129   Message_Msg EPMSG110 ("PrResult.Print.MSG110"); //    Result is Shell                 : %d
130   EPMSG110.Arg (SS);
131   aMessenger->Send (EPMSG110, Message_Info, Standard_True);
132   Message_Msg EPMSG150 ("PrResult.Print.MSG150"); //    No Result                       : %d
133   EPMSG150.Arg (SN);
134   aMessenger->Send (EPMSG150, Message_Info, Standard_True);
135   
136   TCollection_AsciiString tmp110 (EPMSG110.Original()), tmp150  (EPMSG150.Original());
137   EPMSG110.Set (tmp110.ToCString());
138   EPMSG150.Set (tmp150.ToCString());
139
140   Message_Msg TPMSG55 ("PrResult.Print.MSG55"); //  Faces:
141   aMessenger->Send (TPMSG55, Message_Info, Standard_True);
142   Message_Msg EPMSG115 ("PrResult.Print.MSG115"); //    Result is Face                  : %d
143   EPMSG115.Arg (FF);
144   aMessenger->Send (EPMSG115, Message_Info, Standard_True);
145   EPMSG110.Arg (FS);
146   aMessenger->Send (EPMSG110, Message_Info, Standard_True);
147   EPMSG150.Arg (FN);
148   aMessenger->Send (EPMSG150, Message_Info, Standard_True);
149   
150   // preparation ratio
151   Standard_Real SPR = 1, FPR = 1;
152   Standard_Integer STotalR = SS, FTotalR  = FF + FS;
153   Standard_Integer NbS = STotalR + SN, NbF = FTotalR + FN;
154   if (NbS > 0) SPR = 1. * (NbS - SN) / NbS;
155   if (NbF > 0) FPR = 1. * (NbF - FN) / NbF;
156   Message_Msg PMSG200 ("PrResult.Print.MSG200"); //Preparation ratio:
157   aMessenger->Send (PMSG200, Message_Info, Standard_True);
158   Message_Msg PMSG205 ("PrResult.Print.MSG205"); //  Shells: %d per cent
159   PMSG205.Arg ((Standard_Integer) (100 * SPR));
160   aMessenger->Send (PMSG205, Message_Info, Standard_True);
161   Message_Msg PMSG210 ("PrResult.Print.MSG210"); //  Faces : %d per cent
162   PMSG210.Arg ((Standard_Integer) (100 * FPR));
163   aMessenger->Send (PMSG210, Message_Info, Standard_True);
164 }
165