Integration of OCCT 6.5.0 from SVN
[occt.git] / src / ShapeProcessAPI / ShapeProcessAPI_ApplySequence.cxx
1 // File:        ShapeProcessAPI_ApplySequence.cxx
2 // Created:     Tue Jun 22 11:41:11 1999
3 // Author:      data exchange team
4 //              <det@friendox>
5
6
7 #include <ShapeProcessAPI_ApplySequence.ixx>
8 #include <TCollection_AsciiString.hxx>
9 #include <TopoDS_Iterator.hxx>
10 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
11 #include <Message_Messenger.hxx>
12 #include <Message_Msg.hxx>
13 #include <Resource_Manager.hxx>
14 #include <ShapeProcess.hxx>
15 #include <ShapeProcess_OperLibrary.hxx>
16
17 //=======================================================================
18 //function : ShapeProcessAPI_ApplySequence
19 //purpose  : 
20 //=======================================================================
21
22 ShapeProcessAPI_ApplySequence::ShapeProcessAPI_ApplySequence(const Standard_CString rscName, 
23                                                              const Standard_CString seqName)
24 {
25
26   myContext = new ShapeProcess_ShapeContext(rscName);
27   myContext->SetDetalisation ( TopAbs_FACE );
28   TCollection_AsciiString str ( seqName );
29
30   // initialize operators
31   ShapeProcess_OperLibrary::Init ();
32   
33   mySeq = str;
34 }
35
36 //=======================================================================
37 //function : Context
38 //purpose  : 
39 //=======================================================================
40
41 Handle(ShapeProcess_ShapeContext)& ShapeProcessAPI_ApplySequence::Context()
42 {
43   return myContext;
44 }
45
46 //=======================================================================
47 //function : PrepareShape
48 //purpose  : 
49 //=======================================================================
50
51 TopoDS_Shape ShapeProcessAPI_ApplySequence::PrepareShape(const TopoDS_Shape& shape,
52                                                          const Standard_Boolean /*fillmap*/,
53                                                          const TopAbs_ShapeEnum /*until*/)
54 {
55   Handle(Resource_Manager) rsc = myContext->ResourceManager();
56   myContext->Init(shape);
57   
58   TCollection_AsciiString str(mySeq);
59   str += ".exec.op";
60   if ( rsc->Find ( str.ToCString() ) ) {
61     ShapeProcess::Perform ( myContext, mySeq.ToCString() );
62   }
63   
64   return myContext->Result();
65 }
66
67 //=======================================================================
68 //function : ClearMap
69 //purpose  : 
70 //=======================================================================
71
72  void ShapeProcessAPI_ApplySequence::ClearMap() 
73 {
74   //myContext->Map().Clear();
75 }
76
77 //=======================================================================
78 //function : Map
79 //purpose  : 
80 //=======================================================================
81
82 const TopTools_DataMapOfShapeShape& ShapeProcessAPI_ApplySequence::Map() const
83 {
84   return myContext->Map();
85 }
86
87 //=======================================================================
88 //function : PrintPreparationResult
89 //purpose  : 
90 //=======================================================================
91
92 void ShapeProcessAPI_ApplySequence::PrintPreparationResult () const
93 {
94   Standard_Integer SS = 0, SN = 0, FF = 0, FS = 0, FN = 0;
95   for (TopTools_DataMapIteratorOfDataMapOfShapeShape It (myContext->Map()); It.More(); It.Next()) {
96     TopoDS_Shape keyshape = It.Key(), valueshape = It.Value();
97     if (keyshape.ShapeType() == TopAbs_SHELL)
98       if (valueshape.IsNull()) SN++;
99       else SS++;
100     else if (keyshape.ShapeType() == TopAbs_FACE)
101       if (valueshape.IsNull()) FN++;
102       else if (valueshape.ShapeType() == TopAbs_SHELL) FS++;
103       else FF++;
104   }
105   
106   Handle(Message_Messenger) aMessenger = myContext->Messenger();
107
108   // mapping
109   Message_Msg EPMSG100 ("PrResult.Print.MSG100"); //Mapping:
110   aMessenger->Send (EPMSG100, Message_Info, Standard_True);
111   Message_Msg TPMSG50 ("PrResult.Print.MSG50"); //  Shells:
112   aMessenger->Send (TPMSG50, Message_Info, Standard_True);
113   Message_Msg EPMSG110 ("PrResult.Print.MSG110"); //    Result is Shell                 : %d
114   EPMSG110.Arg (SS);
115   aMessenger->Send (EPMSG110, Message_Info, Standard_True);
116   Message_Msg EPMSG150 ("PrResult.Print.MSG150"); //    No Result                       : %d
117   EPMSG150.Arg (SN);
118   aMessenger->Send (EPMSG150, Message_Info, Standard_True);
119   
120   TCollection_AsciiString tmp110 (EPMSG110.Original()), tmp150  (EPMSG150.Original());
121   EPMSG110.Set (tmp110.ToCString());
122   EPMSG150.Set (tmp150.ToCString());
123
124   Message_Msg TPMSG55 ("PrResult.Print.MSG55"); //  Faces:
125   aMessenger->Send (TPMSG55, Message_Info, Standard_True);
126   Message_Msg EPMSG115 ("PrResult.Print.MSG115"); //    Result is Face                  : %d
127   EPMSG115.Arg (FF);
128   aMessenger->Send (EPMSG115, Message_Info, Standard_True);
129   EPMSG110.Arg (FS);
130   aMessenger->Send (EPMSG110, Message_Info, Standard_True);
131   EPMSG150.Arg (FN);
132   aMessenger->Send (EPMSG150, Message_Info, Standard_True);
133   
134   // preparation ratio
135   Standard_Real SPR = 1, FPR = 1;
136   Standard_Integer STotalR = SS, FTotalR  = FF + FS;
137   Standard_Integer NbS = STotalR + SN, NbF = FTotalR + FN;
138   if (NbS > 0) SPR = 1. * (NbS - SN) / NbS;
139   if (NbF > 0) FPR = 1. * (NbF - FN) / NbF;
140   Message_Msg PMSG200 ("PrResult.Print.MSG200"); //Preparation ratio:
141   aMessenger->Send (PMSG200, Message_Info, Standard_True);
142   Message_Msg PMSG205 ("PrResult.Print.MSG205"); //  Shells: %d per cent
143   PMSG205.Arg ((Standard_Integer) (100 * SPR));
144   aMessenger->Send (PMSG205, Message_Info, Standard_True);
145   Message_Msg PMSG210 ("PrResult.Print.MSG210"); //  Faces : %d per cent
146   PMSG210.Arg ((Standard_Integer) (100 * FPR));
147   aMessenger->Send (PMSG210, Message_Info, Standard_True);
148 }
149