| 1 | #include <STEPControl_Writer.ixx> |
| 2 | #include <STEPControl_Controller.hxx> |
| 3 | #include <STEPControl_ActorWrite.hxx> |
| 4 | #include <XSControl_TransferWriter.hxx> |
| 5 | #include <Interface_InterfaceModel.hxx> |
| 6 | #include <Interface_Macros.hxx> |
| 7 | #include <Message_ProgressIndicator.hxx> |
| 8 | #include <TopExp_Explorer.hxx> |
| 9 | #include <Transfer_FinderProcess.hxx> |
| 10 | |
| 11 | |
| 12 | //======================================================================= |
| 13 | //function : STEPControl_Writer |
| 14 | //purpose : |
| 15 | //======================================================================= |
| 16 | |
| 17 | STEPControl_Writer::STEPControl_Writer () |
| 18 | { |
| 19 | STEPControl_Controller::Init(); |
| 20 | SetWS (new XSControl_WorkSession); |
| 21 | } |
| 22 | |
| 23 | |
| 24 | //======================================================================= |
| 25 | //function : STEPControl_Writer |
| 26 | |
| 27 | //purpose : |
| 28 | //======================================================================= |
| 29 | |
| 30 | STEPControl_Writer::STEPControl_Writer |
| 31 | (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch) |
| 32 | { |
| 33 | STEPControl_Controller::Init(); |
| 34 | SetWS (WS,scratch); |
| 35 | } |
| 36 | |
| 37 | |
| 38 | //======================================================================= |
| 39 | //function : SetWS |
| 40 | |
| 41 | //purpose : |
| 42 | //======================================================================= |
| 43 | |
| 44 | void STEPControl_Writer::SetWS(const Handle(XSControl_WorkSession)& WS, |
| 45 | const Standard_Boolean scratch) |
| 46 | { |
| 47 | thesession = WS; |
| 48 | thesession->SelectNorm("STEP"); |
| 49 | thesession->InitTransferReader(0); |
| 50 | Handle(StepData_StepModel) model = Model (scratch); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | //======================================================================= |
| 55 | //function : WS |
| 56 | //purpose : |
| 57 | //======================================================================= |
| 58 | |
| 59 | Handle(XSControl_WorkSession) STEPControl_Writer::WS () const |
| 60 | { |
| 61 | return thesession; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | //======================================================================= |
| 66 | //function : Model |
| 67 | //purpose : |
| 68 | //======================================================================= |
| 69 | |
| 70 | Handle(StepData_StepModel) STEPControl_Writer::Model |
| 71 | (const Standard_Boolean newone) |
| 72 | { |
| 73 | DeclareAndCast(StepData_StepModel,model,thesession->Model()); |
| 74 | if (newone || model.IsNull()) |
| 75 | model = GetCasted(StepData_StepModel,thesession->NewModel()); |
| 76 | return model; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | //======================================================================= |
| 81 | //function : SetTolerance |
| 82 | //purpose : |
| 83 | //======================================================================= |
| 84 | |
| 85 | void STEPControl_Writer::SetTolerance (const Standard_Real Tol) |
| 86 | { |
| 87 | DeclareAndCast(STEPControl_ActorWrite,act,WS()->NormAdaptor()->ActorWrite()); |
| 88 | if (!act.IsNull()) act->SetTolerance (Tol); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | //======================================================================= |
| 93 | //function : UnsetTolerance |
| 94 | //purpose : |
| 95 | //======================================================================= |
| 96 | |
| 97 | void STEPControl_Writer::UnsetTolerance () |
| 98 | { |
| 99 | SetTolerance (-1.); |
| 100 | } |
| 101 | |
| 102 | |
| 103 | //======================================================================= |
| 104 | //function : Transfer |
| 105 | //purpose : |
| 106 | //======================================================================= |
| 107 | |
| 108 | IFSelect_ReturnStatus STEPControl_Writer::Transfer |
| 109 | (const TopoDS_Shape& sh, const STEPControl_StepModelType mode, |
| 110 | const Standard_Boolean compgraph) |
| 111 | { |
| 112 | Standard_Integer mws = -1; |
| 113 | switch (mode) { |
| 114 | case STEPControl_AsIs : mws = 0; break; |
| 115 | case STEPControl_FacetedBrep : mws = 1; break; |
| 116 | case STEPControl_ShellBasedSurfaceModel : mws = 2; break; |
| 117 | case STEPControl_ManifoldSolidBrep : mws = 3; break; |
| 118 | case STEPControl_GeometricCurveSet : mws = 4; break; |
| 119 | default : break; |
| 120 | } |
| 121 | if (mws < 0) return IFSelect_RetError; // cas non reconnu |
| 122 | thesession->SetModeWriteShape (mws); |
| 123 | |
| 124 | // for progress indicator. |
| 125 | Handle(Message_ProgressIndicator) progress = |
| 126 | WS()->TransferWriter()->FinderProcess()->GetProgress(); |
| 127 | if ( ! progress.IsNull() ) { |
| 128 | Standard_Integer nbfaces=0; |
| 129 | for( TopExp_Explorer exp(sh, TopAbs_FACE); exp.More(); exp.Next()) nbfaces++; |
| 130 | progress->SetScale ( "Face", 0, nbfaces, 1 ); |
| 131 | progress->Show(); |
| 132 | } |
| 133 | |
| 134 | return thesession->TransferWriteShape(sh,compgraph); |
| 135 | } |
| 136 | |
| 137 | |
| 138 | //======================================================================= |
| 139 | //function : Write |
| 140 | //purpose : |
| 141 | //======================================================================= |
| 142 | |
| 143 | IFSelect_ReturnStatus STEPControl_Writer::Write (const Standard_CString filename) |
| 144 | { |
| 145 | return thesession->SendAll(filename); |
| 146 | } |
| 147 | |
| 148 | |
| 149 | //======================================================================= |
| 150 | //function : PrintStatsTransfer |
| 151 | //purpose : |
| 152 | //======================================================================= |
| 153 | |
| 154 | void STEPControl_Writer::PrintStatsTransfer |
| 155 | (const Standard_Integer what, const Standard_Integer mode) const |
| 156 | { |
| 157 | thesession->TransferWriter()->PrintStats (what,mode); |
| 158 | } |