0024788: Foundation Classes - remove Dico_Dictionary
[occt.git] / src / ShapeProcess / ShapeProcess.cxx
CommitLineData
b311480e 1// Created on: 2000-08-21
2// Created by: Andrey BETENEV
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
997e128f 16#include <NCollection_DataMap.hxx>
42cf5bc1 17#include <Message_Messenger.hxx>
18#include <Message_Msg.hxx>
19#include <ShapeProcess.hxx>
20#include <ShapeProcess_Context.hxx>
42cf5bc1 21#include <ShapeProcess_Operator.hxx>
7fd59977 22#include <Standard_ErrorHandler.hxx>
23#include <Standard_Failure.hxx>
24#include <TCollection_AsciiString.hxx>
25#include <TColStd_SequenceOfAsciiString.hxx>
26
997e128f 27static NCollection_DataMap<TCollection_AsciiString, Handle(ShapeProcess_Operator)> aMapOfOperators;
7fd59977 28//=======================================================================
29//function : RegisterOperator
30//purpose :
31//=======================================================================
32
33Standard_Boolean ShapeProcess::RegisterOperator (const Standard_CString name,
34 const Handle(ShapeProcess_Operator)& op)
35{
997e128f 36 if (aMapOfOperators.IsBound(name)) {
0797d9d3 37#ifdef OCCT_DEBUG
7fd59977 38 cout << "Warning: operator with name " << name << " is already registered!" << endl;
39#endif
40 return Standard_False;
41 }
997e128f 42 aMapOfOperators.Bind( name, op );
7fd59977 43 return Standard_True;
44}
45
46//=======================================================================
47//function : FindOperator
48//purpose :
49//=======================================================================
50
51Standard_Boolean ShapeProcess::FindOperator (const Standard_CString name,
52 Handle(ShapeProcess_Operator)& op)
53{
997e128f 54 if (!aMapOfOperators.IsBound(name)) {
0797d9d3 55#ifdef OCCT_DEBUG
7fd59977 56 cout << "Error: no operator with name " << name << " registered!" << endl;
57#endif
58 return Standard_False;
59 }
997e128f 60 op = aMapOfOperators.ChangeFind(name);
7fd59977 61 return !op.IsNull();
62}
63
64//=======================================================================
65//function : Perform
66//purpose :
67//=======================================================================
68
69Standard_Boolean ShapeProcess::Perform (const Handle(ShapeProcess_Context)& context,
70 const Standard_CString seq)
71{
72 context->SetScope ( seq );
73
74 // get description of the sequence
75 TCollection_AsciiString sequence;
76 if ( ! context->GetString ( "exec.op", sequence ) ) {
0797d9d3 77#ifdef OCCT_DEBUG
7fd59977 78 cout << "Error: ShapeProcess_Performer::Perform: sequence not defined for " << seq << endl;
79#endif
881536e2 80 if ( context->TraceLevel() >0 ) {
81 Message_Msg SMSG3 ("SP.Sequence.Warn.NoSeq"); // Sequence %s not found
82 context->Messenger()->Send (SMSG3 << seq, Message_Warning);
83 }
7fd59977 84 context->UnSetScope();
85 return Standard_False;
86 }
87 TColStd_SequenceOfAsciiString sequenceOfOperators;
88 TCollection_AsciiString oper;
89 Standard_Integer i;
90 for ( i=1; ; i++ ) {
91 oper = sequence.Token ( " \t,;", i );
92 if ( oper.Length() <=0 ) break;
93 sequenceOfOperators.Append(oper);
94 }
95
96 // put a message
97 if ( context->TraceLevel() >=2 ) {
881536e2 98 Message_Msg SMSG0 ("SP.Sequence.Info.Seq"); //Sequence of operators: %s
7fd59977 99 TCollection_AsciiString Seq;
100 for ( Standard_Integer i1=1; i1 <= sequenceOfOperators.Length(); i1++ ) {
101 if (i1 > 1) Seq += ",";
102 Seq += sequenceOfOperators.Value(i1);
103 }
104 SMSG0.Arg (Seq.ToCString());
105 context->Messenger()->Send (SMSG0, Message_Info);
106 }
107
108 // iterate on operators in the sequence
881536e2 109 Standard_Boolean isDone = Standard_False;
7fd59977 110 for (i=1; i<=sequenceOfOperators.Length(); i++) {
111 oper = sequenceOfOperators.Value(i);
112
113 if ( context->TraceLevel() >=2 ) {
881536e2 114 Message_Msg SMSG5 ("SP.Sequence.Info.Operator"); //Operator %d/%d: %s
7fd59977 115 SMSG5 << i << sequenceOfOperators.Length() << oper.ToCString();
116 context->Messenger()->Send (SMSG5, Message_Alarm);
117 }
118
119 Handle(ShapeProcess_Operator) op;
120 if ( ! ShapeProcess::FindOperator ( oper.ToCString(), op ) ) {
121 if ( context->TraceLevel() >0 ) {
881536e2 122 Message_Msg SMSG1 ("SP.Sequence.Error.NoOp"); //Operator %s not found
7fd59977 123 context->Messenger()->Send (SMSG1 << oper, Message_Alarm);
124 }
125 continue;
126 }
127
128 context->SetScope ( oper.ToCString() );
129 try {
130 OCC_CATCH_SIGNALS
881536e2 131 if ( op->Perform(context) )
132 isDone = Standard_True;
7fd59977 133 }
134 catch (Standard_Failure) {
881536e2 135 Message_Msg SMSG2 ("SP.Sequence.Error.Except"); //Operator %s failed with exception %s
7fd59977 136 SMSG2 << oper << Standard_Failure::Caught()->GetMessageString();
137 context->Messenger()->Send (SMSG2, Message_Alarm);
138 }
139 context->UnSetScope();
140 }
141
142 context->UnSetScope();
881536e2 143 return isDone;
7fd59977 144}