0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / ShapeProcessAPI / ShapeProcessAPI_ApplySequence.cxx
CommitLineData
b311480e 1// Created on: 1999-06-22
2// Created by: data exchange team
3// Copyright (c) 1999-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
7fd59977 18#include <Message_Messenger.hxx>
19#include <Message_Msg.hxx>
20#include <Resource_Manager.hxx>
21#include <ShapeProcess.hxx>
22#include <ShapeProcess_OperLibrary.hxx>
42cf5bc1 23#include <ShapeProcess_ShapeContext.hxx>
24#include <ShapeProcessAPI_ApplySequence.hxx>
25#include <TCollection_AsciiString.hxx>
42cf5bc1 26#include <TopoDS_Shape.hxx>
27#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
7fd59977 28
29//=======================================================================
30//function : ShapeProcessAPI_ApplySequence
31//purpose :
32//=======================================================================
7fd59977 33ShapeProcessAPI_ApplySequence::ShapeProcessAPI_ApplySequence(const Standard_CString rscName,
34 const Standard_CString seqName)
35{
36
37 myContext = new ShapeProcess_ShapeContext(rscName);
38 myContext->SetDetalisation ( TopAbs_FACE );
39 TCollection_AsciiString str ( seqName );
40
41 // initialize operators
42 ShapeProcess_OperLibrary::Init ();
43
44 mySeq = str;
45}
46
47//=======================================================================
48//function : Context
49//purpose :
50//=======================================================================
51
52Handle(ShapeProcess_ShapeContext)& ShapeProcessAPI_ApplySequence::Context()
53{
54 return myContext;
55}
56
57//=======================================================================
58//function : PrepareShape
59//purpose :
60//=======================================================================
61
62TopoDS_Shape ShapeProcessAPI_ApplySequence::PrepareShape(const TopoDS_Shape& shape,
63 const Standard_Boolean /*fillmap*/,
64 const TopAbs_ShapeEnum /*until*/)
65{
e4ff2bbb 66 if (shape.IsNull())
67 return shape;
7fd59977 68 Handle(Resource_Manager) rsc = myContext->ResourceManager();
69 myContext->Init(shape);
70
71 TCollection_AsciiString str(mySeq);
72 str += ".exec.op";
73 if ( rsc->Find ( str.ToCString() ) ) {
74 ShapeProcess::Perform ( myContext, mySeq.ToCString() );
75 }
76
77 return myContext->Result();
78}
79
80//=======================================================================
81//function : ClearMap
82//purpose :
83//=======================================================================
84
85 void ShapeProcessAPI_ApplySequence::ClearMap()
86{
87 //myContext->Map().Clear();
88}
89
90//=======================================================================
91//function : Map
92//purpose :
93//=======================================================================
94
95const TopTools_DataMapOfShapeShape& ShapeProcessAPI_ApplySequence::Map() const
96{
97 return myContext->Map();
98}
99
100//=======================================================================
101//function : PrintPreparationResult
102//purpose :
103//=======================================================================
104
105void ShapeProcessAPI_ApplySequence::PrintPreparationResult () const
106{
107 Standard_Integer SS = 0, SN = 0, FF = 0, FS = 0, FN = 0;
108 for (TopTools_DataMapIteratorOfDataMapOfShapeShape It (myContext->Map()); It.More(); It.Next()) {
109 TopoDS_Shape keyshape = It.Key(), valueshape = It.Value();
eafb234b 110 if (keyshape.ShapeType() == TopAbs_SHELL) {
7fd59977 111 if (valueshape.IsNull()) SN++;
112 else SS++;
eafb234b 113 }
114 else if (keyshape.ShapeType() == TopAbs_FACE) {
7fd59977 115 if (valueshape.IsNull()) FN++;
116 else if (valueshape.ShapeType() == TopAbs_SHELL) FS++;
117 else FF++;
eafb234b 118 }
7fd59977 119 }
120
121 Handle(Message_Messenger) aMessenger = myContext->Messenger();
122
123 // mapping
124 Message_Msg EPMSG100 ("PrResult.Print.MSG100"); //Mapping:
fa8a4628 125 aMessenger->Send (EPMSG100, Message_Info);
7fd59977 126 Message_Msg TPMSG50 ("PrResult.Print.MSG50"); // Shells:
fa8a4628 127 aMessenger->Send (TPMSG50, Message_Info);
7fd59977 128 Message_Msg EPMSG110 ("PrResult.Print.MSG110"); // Result is Shell : %d
129 EPMSG110.Arg (SS);
fa8a4628 130 aMessenger->Send (EPMSG110, Message_Info);
7fd59977 131 Message_Msg EPMSG150 ("PrResult.Print.MSG150"); // No Result : %d
132 EPMSG150.Arg (SN);
fa8a4628 133 aMessenger->Send (EPMSG150, Message_Info);
7fd59977 134
135 TCollection_AsciiString tmp110 (EPMSG110.Original()), tmp150 (EPMSG150.Original());
136 EPMSG110.Set (tmp110.ToCString());
137 EPMSG150.Set (tmp150.ToCString());
138
139 Message_Msg TPMSG55 ("PrResult.Print.MSG55"); // Faces:
fa8a4628 140 aMessenger->Send (TPMSG55, Message_Info);
7fd59977 141 Message_Msg EPMSG115 ("PrResult.Print.MSG115"); // Result is Face : %d
142 EPMSG115.Arg (FF);
fa8a4628 143 aMessenger->Send (EPMSG115, Message_Info);
7fd59977 144 EPMSG110.Arg (FS);
fa8a4628 145 aMessenger->Send (EPMSG110, Message_Info);
7fd59977 146 EPMSG150.Arg (FN);
fa8a4628 147 aMessenger->Send (EPMSG150, Message_Info);
7fd59977 148
149 // preparation ratio
150 Standard_Real SPR = 1, FPR = 1;
151 Standard_Integer STotalR = SS, FTotalR = FF + FS;
152 Standard_Integer NbS = STotalR + SN, NbF = FTotalR + FN;
153 if (NbS > 0) SPR = 1. * (NbS - SN) / NbS;
154 if (NbF > 0) FPR = 1. * (NbF - FN) / NbF;
155 Message_Msg PMSG200 ("PrResult.Print.MSG200"); //Preparation ratio:
fa8a4628 156 aMessenger->Send (PMSG200, Message_Info);
7fd59977 157 Message_Msg PMSG205 ("PrResult.Print.MSG205"); // Shells: %d per cent
158 PMSG205.Arg ((Standard_Integer) (100 * SPR));
fa8a4628 159 aMessenger->Send (PMSG205, Message_Info);
7fd59977 160 Message_Msg PMSG210 ("PrResult.Print.MSG210"); // Faces : %d per cent
161 PMSG210.Arg ((Standard_Integer) (100 * FPR));
fa8a4628 162 aMessenger->Send (PMSG210, Message_Info);
7fd59977 163}
164