FreeCAD

Форк
0
/
ImportIges.cpp 
127 строк · 5.1 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
# include <fcntl.h>
26
# include <BRep_Builder.hxx>
27
# include <IGESBasic_Group.hxx>
28
# include <IGESBasic_SingularSubfigure.hxx>
29
# include <IGESControl_Controller.hxx>
30
# include <IGESControl_Reader.hxx>
31
# include <IGESSolid_ManifoldSolid.hxx>
32
# include <Message_MsgFile.hxx>
33
# include <Standard_Version.hxx>
34
# include <TColStd_HSequenceOfTransient.hxx>
35
# include <TopoDS.hxx>
36
# include <TopoDS_Compound.hxx>
37
# include <TopoDS_Shape.hxx>
38
# include <Transfer_TransientProcess.hxx>
39
# include <XSControl_TransferReader.hxx>
40
# include <XSControl_WorkSession.hxx>
41
#endif
42

43
#include <App/Document.h>
44
#include <Base/Sequencer.h>
45

46
#include "ImportIges.h"
47
#include "PartFeature.h"
48
#include "ProgressIndicator.h"
49

50

51
using namespace Part;
52

53
int Part::ImportIgesParts(App::Document *pcDoc, const char* FileName)
54
{
55
    try {
56
        Base::FileInfo fi(FileName);
57
        // read iges file
58
        IGESControl_Controller::Init();
59

60
        // load data exchange message files
61
        Message_MsgFile::LoadFromEnv("CSF_XSMessage","IGES");
62

63
        // load shape healing message files
64
        Message_MsgFile::LoadFromEnv("CSF_SHMessageStd","SHAPEStd");
65

66
        IGESControl_Reader aReader;
67
        if (aReader.ReadFile((Standard_CString)FileName) != IFSelect_RetDone)
68
            throw Base::FileException("Error in reading IGES");
69

70
        // Ignore construction elements
71
        // http://www.opencascade.org/org/forum/thread_20603/?forum=3
72
        aReader.SetReadVisible(Standard_True);
73

74
        // check file conformity and output stats
75
        aReader.PrintCheckLoad(Standard_True,IFSelect_GeneralInfo);
76

77
        std::string aName = fi.fileNamePure();
78
#if OCC_VERSION_HEX < 0x070500
79
        Handle(Message_ProgressIndicator) pi = new ProgressIndicator(100);
80
        pi->NewScope(100, "Reading IGES file...");
81
        pi->Show();
82
        aReader.WS()->MapReader()->SetProgress(pi);
83
#endif
84

85
        // make model
86
        aReader.ClearShapes();
87
        //Standard_Integer nbRootsForTransfer = aReader.NbRootsForTransfer();
88
        aReader.TransferRoots();
89
#if OCC_VERSION_HEX < 0x070500
90
        pi->EndScope();
91
#endif
92

93
        // put all other free-flying shapes into a single compound
94
        Standard_Boolean emptyComp = Standard_True;
95
        BRep_Builder builder;
96
        TopoDS_Compound comp;
97
        builder.MakeCompound(comp);
98

99
        Standard_Integer nbShapes = aReader.NbShapes();
100
        for (Standard_Integer i=1; i<=nbShapes; i++) {
101
            TopoDS_Shape aShape = aReader.Shape(i);
102
            if (!aShape.IsNull()) {
103
                if (aShape.ShapeType() == TopAbs_SOLID ||
104
                    aShape.ShapeType() == TopAbs_COMPOUND ||
105
                    aShape.ShapeType() == TopAbs_SHELL) {
106
                        App::DocumentObject* obj = pcDoc->addObject("Part::Feature", aName.c_str());
107
                        static_cast<Part::Feature*>(obj)->Shape.setValue(aShape);
108
                }
109
                else {
110
                    builder.Add(comp, aShape);
111
                    emptyComp = Standard_False;
112
                }
113
            }
114
        }
115
        if (!emptyComp) {
116
            std::string name = fi.fileNamePure();
117
            Part::Feature *pcFeature = static_cast<Part::Feature*>(pcDoc->addObject
118
                ("Part::Feature", name.c_str()));
119
            pcFeature->Shape.setValue(comp);
120
        }
121
    }
122
    catch (Standard_Failure& e) {
123
        throw Base::CADKernelError(e.GetMessageString());
124
    }
125

126
    return 0;
127
}
128

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.