summaryrefslogtreecommitdiff
path: root/src/ShapeProcessAPI/ShapeProcessAPI_ApplySequence.cxx
blob: ebfe1d309735920b68c6e4e84c13d01bea83516c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// File:	ShapeProcessAPI_ApplySequence.cxx
// Created:	Tue Jun 22 11:41:11 1999
// Author:	data exchange team
//		<det@friendox>


#include <ShapeProcessAPI_ApplySequence.ixx>
#include <TCollection_AsciiString.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
#include <Message_Messenger.hxx>
#include <Message_Msg.hxx>
#include <Resource_Manager.hxx>
#include <ShapeProcess.hxx>
#include <ShapeProcess_OperLibrary.hxx>

//=======================================================================
//function : ShapeProcessAPI_ApplySequence
//purpose  : 
//=======================================================================

ShapeProcessAPI_ApplySequence::ShapeProcessAPI_ApplySequence(const Standard_CString rscName, 
							     const Standard_CString seqName)
{

  myContext = new ShapeProcess_ShapeContext(rscName);
  myContext->SetDetalisation ( TopAbs_FACE );
  TCollection_AsciiString str ( seqName );

  // initialize operators
  ShapeProcess_OperLibrary::Init ();
  
  mySeq = str;
}

//=======================================================================
//function : Context
//purpose  : 
//=======================================================================

Handle(ShapeProcess_ShapeContext)& ShapeProcessAPI_ApplySequence::Context()
{
  return myContext;
}

//=======================================================================
//function : PrepareShape
//purpose  : 
//=======================================================================

TopoDS_Shape ShapeProcessAPI_ApplySequence::PrepareShape(const TopoDS_Shape& shape,
                                                         const Standard_Boolean /*fillmap*/,
                                                         const TopAbs_ShapeEnum /*until*/)
{
  Handle(Resource_Manager) rsc = myContext->ResourceManager();
  myContext->Init(shape);
  
  TCollection_AsciiString str(mySeq);
  str += ".exec.op";
  if ( rsc->Find ( str.ToCString() ) ) {
    ShapeProcess::Perform ( myContext, mySeq.ToCString() );
  }
  
  return myContext->Result();
}

//=======================================================================
//function : ClearMap
//purpose  : 
//=======================================================================

 void ShapeProcessAPI_ApplySequence::ClearMap() 
{
  //myContext->Map().Clear();
}

//=======================================================================
//function : Map
//purpose  : 
//=======================================================================

const TopTools_DataMapOfShapeShape& ShapeProcessAPI_ApplySequence::Map() const
{
  return myContext->Map();
}

//=======================================================================
//function : PrintPreparationResult
//purpose  : 
//=======================================================================

void ShapeProcessAPI_ApplySequence::PrintPreparationResult () const
{
  Standard_Integer SS = 0, SN = 0, FF = 0, FS = 0, FN = 0;
  for (TopTools_DataMapIteratorOfDataMapOfShapeShape It (myContext->Map()); It.More(); It.Next()) {
    TopoDS_Shape keyshape = It.Key(), valueshape = It.Value();
    if (keyshape.ShapeType() == TopAbs_SHELL) {
      if (valueshape.IsNull()) SN++;
      else SS++;
    }
    else if (keyshape.ShapeType() == TopAbs_FACE) {
      if (valueshape.IsNull()) FN++;
      else if (valueshape.ShapeType() == TopAbs_SHELL) FS++;
      else FF++;
    }
  }
  
  Handle(Message_Messenger) aMessenger = myContext->Messenger();

  // mapping
  Message_Msg EPMSG100 ("PrResult.Print.MSG100"); //Mapping:
  aMessenger->Send (EPMSG100, Message_Info, Standard_True);
  Message_Msg TPMSG50 ("PrResult.Print.MSG50"); //  Shells:
  aMessenger->Send (TPMSG50, Message_Info, Standard_True);
  Message_Msg EPMSG110 ("PrResult.Print.MSG110"); //    Result is Shell                 : %d
  EPMSG110.Arg (SS);
  aMessenger->Send (EPMSG110, Message_Info, Standard_True);
  Message_Msg EPMSG150 ("PrResult.Print.MSG150"); //    No Result                       : %d
  EPMSG150.Arg (SN);
  aMessenger->Send (EPMSG150, Message_Info, Standard_True);
  
  TCollection_AsciiString tmp110 (EPMSG110.Original()), tmp150  (EPMSG150.Original());
  EPMSG110.Set (tmp110.ToCString());
  EPMSG150.Set (tmp150.ToCString());

  Message_Msg TPMSG55 ("PrResult.Print.MSG55"); //  Faces:
  aMessenger->Send (TPMSG55, Message_Info, Standard_True);
  Message_Msg EPMSG115 ("PrResult.Print.MSG115"); //    Result is Face                  : %d
  EPMSG115.Arg (FF);
  aMessenger->Send (EPMSG115, Message_Info, Standard_True);
  EPMSG110.Arg (FS);
  aMessenger->Send (EPMSG110, Message_Info, Standard_True);
  EPMSG150.Arg (FN);
  aMessenger->Send (EPMSG150, Message_Info, Standard_True);
  
  // preparation ratio
  Standard_Real SPR = 1, FPR = 1;
  Standard_Integer STotalR = SS, FTotalR  = FF + FS;
  Standard_Integer NbS = STotalR + SN, NbF = FTotalR + FN;
  if (NbS > 0) SPR = 1. * (NbS - SN) / NbS;
  if (NbF > 0) FPR = 1. * (NbF - FN) / NbF;
  Message_Msg PMSG200 ("PrResult.Print.MSG200"); //Preparation ratio:
  aMessenger->Send (PMSG200, Message_Info, Standard_True);
  Message_Msg PMSG205 ("PrResult.Print.MSG205"); //  Shells: %d per cent
  PMSG205.Arg ((Standard_Integer) (100 * SPR));
  aMessenger->Send (PMSG205, Message_Info, Standard_True);
  Message_Msg PMSG210 ("PrResult.Print.MSG210"); //  Faces : %d per cent
  PMSG210.Arg ((Standard_Integer) (100 * FPR));
  aMessenger->Send (PMSG210, Message_Info, Standard_True);
}