Adding svn:eol-style=LF property
[occt.git] / samples / qt / Graphic3dDemo / src / Translate.cxx
... / ...
CommitLineData
1#include <qfiledialog.h>
2#include <qmessagebox.h>
3#include <qapplication.h>
4
5#include "Translate.h"
6#include "Application.h"
7#include "Document.h"
8#include "MDIWindow.h"
9#include "global.h"
10
11#include <StlAPI_Writer.hxx>
12#include <AIS_InteractiveObject.hxx>
13#include <AIS_Shape.hxx>
14#include <TopoDS_Shape.hxx>
15#include <BRep_Builder.hxx>
16#include <BRepTools.hxx>
17#include <TopExp_Explorer.hxx>
18#include <BRep_Tool.hxx>
19#include <TopoDS.hxx>
20#include <Geom_Surface.hxx>
21#include <Geom_Plane.hxx>
22#include <Geom_Line.hxx>
23#include <PTColStd_TransientPersistentMap.hxx>
24#include <TopoDS_Compound.hxx>
25#include <AIS_ListOfInteractive.hxx>
26#include <AIS_ListIteratorOfListOfInteractive.hxx>
27
28
29// STL
30//#include <Mesh_InteractiveObject.hxx>
31//#include <Mesh_STLRead.hxx>
32//#include <Mesh_Drawer.hxx>
33//#include <Mesh_Model.hxx>
34
35#ifdef a
36#include "OSD_Timer.hxx"
37#include <FSD_File.hxx>
38#include <ShapeSchema.hxx>
39#include <Storage_Data.hxx>
40#include <PTopoDS_HShape.hxx>
41#include <Storage_HSeqOfRoot.hxx>
42#include <Storage_Root.hxx>
43#include <PTColStd_PersistentTransientMap.hxx>
44#include <MgtBRep.hxx>
45#include <TCollection_ExtendedString.hxx>
46#include <IGESControl_Reader.hxx>
47#include <IGESControl_Controller.hxx>
48#include <IGESControl_Writer.hxx>
49#include <Interface_Static.hxx>
50#include <STEPControl_Reader.hxx>
51#include <Interface_TraceFile.hxx>
52#include <STEPControl_Writer.hxx>
53#include <TColStd_SequenceOfAsciiString.hxx>
54#include <TColStd_SequenceOfExtendedString.hxx>
55#include <VrmlAPI_Writer.hxx>
56#endif
57
58Translate::Translate( QObject* parent ):
59QObject( parent )
60{
61}
62
63Translate::~Translate()
64{
65}
66
67/*!
68 Selects a file from standard dialog acoording to selection
69 'filter'
70*/
71QString Translate::selectFileName( const QString& filter, bool isImport ) const
72{
73 return isImport ?
74 QFileDialog::getOpenFileName( QApplication::activeWindow(), tr("INF_APP_IMPORT"), QString::null, filter ) :
75 QFileDialog::getSaveFileName( QApplication::activeWindow(), tr("INF_APP_EXPORT"), QString::null, filter );
76 /*
77 QFileDialog fd ( 0, 0, true );
78 fd.setFilters( filter );
79 if(isImport)
80 fd.setCaption ( tr("INF_APP_IMPORT") );
81 int ret = fd.exec();
82
83 qApp->processEvents();
84
85 return ( ret == QDialog::Accepted ? fd.selectedFile() : QString::null );
86 */
87}
88
89Handle(TopTools_HSequenceOfShape)
90Translate::BuildSequenceFromContext(const Handle(AIS_InteractiveContext)& cxt)
91{
92 Handle(TopTools_HSequenceOfShape) sequence = new TopTools_HSequenceOfShape();
93 Handle(AIS_InteractiveObject) object;
94 AIS_ListOfInteractive displayed;
95 cxt->DisplayedObjects( displayed );
96
97 AIS_ListIteratorOfListOfInteractive it( displayed );
98 for ( ; it.More(); it.Next() ) {
99 object = it.Value();
100 if ( object->IsKind( STANDARD_TYPE( AIS_Shape ) ) ) {
101 TopoDS_Shape shape = Handle(AIS_Shape)::DownCast( object )->Shape();
102 sequence->Append( shape );
103 }
104 }
105
106#ifdef OLD_CODE
107 for(anInteractiveContext->InitCurrent();anInteractiveContext->MoreCurrent();anInteractiveContext->NextCurrent())
108 {
109 picked = anInteractiveContext->Current();
110 if (anInteractiveContext->Current()->IsKind(STANDARD_TYPE(AIS_Shape)))
111 {
112 TopoDS_Shape aShape = Handle(AIS_Shape)::DownCast(picked)->Shape();
113 aSequence->Append(aShape);
114 }
115 }
116#endif //OLD_CODE
117 return sequence;
118}
119
120void Translate::importBREP(const Handle(AIS_InteractiveContext) theContext)
121{
122 static QString filter = "BREP Files (*.brep )";
123 importBREP(theContext,filter);
124}
125
126void Translate::importBREP(const Handle(AIS_InteractiveContext) theContext, const QString& filter)
127{
128 QString file = selectFileName( filter, true );
129 if ( !file.isNull() ) {
130 QApplication::setOverrideCursor( Qt::WaitCursor );
131 if(!importBREP(theContext, (const Standard_CString) file.toLatin1().constData())) {
132 QApplication::restoreOverrideCursor();
133 QMessageBox::information ( QApplication::activeWindow(),tr("TIT_ERROR"), tr("INF_TRANSLATE_ERROR"), tr("BTN_OK"),
134 QString::null, QString::null, 0, 0);
135 qApp->processEvents(); /* update desktop */
136 } else
137 QApplication::restoreOverrideCursor();
138 }
139}
140
141bool Translate::importBREP(const Handle(AIS_InteractiveContext) theContext, const Standard_CString theFileName)
142{
143 Handle(TopTools_HSequenceOfShape) aSequence = new TopTools_HSequenceOfShape();
144 TopoDS_Shape aShape;
145 BRep_Builder aBuilder;
146
147 Application::startTimer();
148 Standard_Boolean result = BRepTools::Read(aShape,theFileName,aBuilder);
149 Application::stopTimer( 0, "Loading BREP file" );
150
151 if(result)
152 aSequence->Append(aShape);
153
154 int curMode =
155 ( (MDIWindow*)Application::getApplication()->getActiveMDI() )->getDisplayMode();
156
157 for(int i=1;i<= aSequence->Length();i++) {
158
159 Application::startTimer();
160 Handle(AIS_Shape) shape = new AIS_Shape( aSequence->Value( i ) );
161 Application::stopTimer( 0, "Build shape" );
162 Application::startTimer();
163 theContext->Display( shape, curMode, 0, false );
164 Application::stopTimer( 0, "Display" );
165 }
166 Application::startTimer();
167 theContext->UpdateCurrentViewer();
168 Application::stopTimer( 0, "Update" );
169
170 return result;
171}
172