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 | |
7fd59977 |
16 | |
42cf5bc1 |
17 | #include <Message_Messenger.hxx> |
18 | #include <Message_Msg.hxx> |
19 | #include <ShapeProcess.hxx> |
20 | #include <ShapeProcess_Context.hxx> |
21 | #include <ShapeProcess_DictionaryOfOperator.hxx> |
22 | #include <ShapeProcess_Operator.hxx> |
7fd59977 |
23 | #include <Standard_ErrorHandler.hxx> |
24 | #include <Standard_Failure.hxx> |
25 | #include <TCollection_AsciiString.hxx> |
26 | #include <TColStd_SequenceOfAsciiString.hxx> |
27 | |
7fd59977 |
28 | static Handle(ShapeProcess_DictionaryOfOperator) dic; |
29 | |
30 | //======================================================================= |
31 | //function : RegisterOperator |
32 | //purpose : |
33 | //======================================================================= |
34 | |
35 | Standard_Boolean ShapeProcess::RegisterOperator (const Standard_CString name, |
36 | const Handle(ShapeProcess_Operator)& op) |
37 | { |
38 | if ( dic.IsNull() ) dic = new ShapeProcess_DictionaryOfOperator; |
39 | if ( dic->HasItem ( name, Standard_True ) ) { |
0797d9d3 |
40 | #ifdef OCCT_DEBUG |
7fd59977 |
41 | cout << "Warning: operator with name " << name << " is already registered!" << endl; |
42 | #endif |
43 | return Standard_False; |
44 | } |
45 | dic->SetItem ( name, op ); |
46 | return Standard_True; |
47 | } |
48 | |
49 | //======================================================================= |
50 | //function : FindOperator |
51 | //purpose : |
52 | //======================================================================= |
53 | |
54 | Standard_Boolean ShapeProcess::FindOperator (const Standard_CString name, |
55 | Handle(ShapeProcess_Operator)& op) |
56 | { |
57 | if ( dic.IsNull() ) dic = new ShapeProcess_DictionaryOfOperator; |
58 | if ( ! dic->HasItem ( name, Standard_True ) ) { |
0797d9d3 |
59 | #ifdef OCCT_DEBUG |
7fd59977 |
60 | cout << "Error: no operator with name " << name << " registered!" << endl; |
61 | #endif |
62 | return Standard_False; |
63 | } |
64 | op = dic->Item ( name ); |
65 | return !op.IsNull(); |
66 | } |
67 | |
68 | //======================================================================= |
69 | //function : Perform |
70 | //purpose : |
71 | //======================================================================= |
72 | |
73 | Standard_Boolean ShapeProcess::Perform (const Handle(ShapeProcess_Context)& context, |
74 | const Standard_CString seq) |
75 | { |
76 | context->SetScope ( seq ); |
77 | |
78 | // get description of the sequence |
79 | TCollection_AsciiString sequence; |
80 | if ( ! context->GetString ( "exec.op", sequence ) ) { |
0797d9d3 |
81 | #ifdef OCCT_DEBUG |
7fd59977 |
82 | cout << "Error: ShapeProcess_Performer::Perform: sequence not defined for " << seq << endl; |
83 | #endif |
881536e2 |
84 | if ( context->TraceLevel() >0 ) { |
85 | Message_Msg SMSG3 ("SP.Sequence.Warn.NoSeq"); // Sequence %s not found |
86 | context->Messenger()->Send (SMSG3 << seq, Message_Warning); |
87 | } |
7fd59977 |
88 | context->UnSetScope(); |
89 | return Standard_False; |
90 | } |
91 | TColStd_SequenceOfAsciiString sequenceOfOperators; |
92 | TCollection_AsciiString oper; |
93 | Standard_Integer i; |
94 | for ( i=1; ; i++ ) { |
95 | oper = sequence.Token ( " \t,;", i ); |
96 | if ( oper.Length() <=0 ) break; |
97 | sequenceOfOperators.Append(oper); |
98 | } |
99 | |
100 | // put a message |
101 | if ( context->TraceLevel() >=2 ) { |
881536e2 |
102 | Message_Msg SMSG0 ("SP.Sequence.Info.Seq"); //Sequence of operators: %s |
7fd59977 |
103 | TCollection_AsciiString Seq; |
104 | for ( Standard_Integer i1=1; i1 <= sequenceOfOperators.Length(); i1++ ) { |
105 | if (i1 > 1) Seq += ","; |
106 | Seq += sequenceOfOperators.Value(i1); |
107 | } |
108 | SMSG0.Arg (Seq.ToCString()); |
109 | context->Messenger()->Send (SMSG0, Message_Info); |
110 | } |
111 | |
112 | // iterate on operators in the sequence |
881536e2 |
113 | Standard_Boolean isDone = Standard_False; |
7fd59977 |
114 | for (i=1; i<=sequenceOfOperators.Length(); i++) { |
115 | oper = sequenceOfOperators.Value(i); |
116 | |
117 | if ( context->TraceLevel() >=2 ) { |
881536e2 |
118 | Message_Msg SMSG5 ("SP.Sequence.Info.Operator"); //Operator %d/%d: %s |
7fd59977 |
119 | SMSG5 << i << sequenceOfOperators.Length() << oper.ToCString(); |
120 | context->Messenger()->Send (SMSG5, Message_Alarm); |
121 | } |
122 | |
123 | Handle(ShapeProcess_Operator) op; |
124 | if ( ! ShapeProcess::FindOperator ( oper.ToCString(), op ) ) { |
125 | if ( context->TraceLevel() >0 ) { |
881536e2 |
126 | Message_Msg SMSG1 ("SP.Sequence.Error.NoOp"); //Operator %s not found |
7fd59977 |
127 | context->Messenger()->Send (SMSG1 << oper, Message_Alarm); |
128 | } |
129 | continue; |
130 | } |
131 | |
132 | context->SetScope ( oper.ToCString() ); |
133 | try { |
134 | OCC_CATCH_SIGNALS |
881536e2 |
135 | if ( op->Perform(context) ) |
136 | isDone = Standard_True; |
7fd59977 |
137 | } |
138 | catch (Standard_Failure) { |
881536e2 |
139 | Message_Msg SMSG2 ("SP.Sequence.Error.Except"); //Operator %s failed with exception %s |
7fd59977 |
140 | SMSG2 << oper << Standard_Failure::Caught()->GetMessageString(); |
141 | context->Messenger()->Send (SMSG2, Message_Alarm); |
142 | } |
143 | context->UnSetScope(); |
144 | } |
145 | |
146 | context->UnSetScope(); |
881536e2 |
147 | return isDone; |
7fd59977 |
148 | } |