OpenCasCade – 载入IGES文件
本例是仿照官方示例 ImportExport,如图:
来实现的,说明下大概流程以及自己尝试的方法,遇到的问题,以及如何解决的。
添加 ImportIGES 消息处理函数
1. 添加事件菜单
如图,在 IDR_MAINFRAME 的菜单栏中添加 Import…->IGES 二级菜单(以后写载入其他格式的文件都在此)。
2. 在 IGES 上右键选择 添加事件处理程序
void OnImportIGES(),(放在doc类中)
3. 在 Doc 类中 添加三个 ReadIGES 函数
1 2 3 4 5 6 |
void CHuiStyleDoc::ReadIGES(const Handle(AIS_InteractiveContext)& anInteractiveContext) { Handle(TopTools_HSequenceOfShape) aSequence = CHuiStyleDoc::ReadIGES(); for(int i=1;i<= aSequence->Length();i++) anInteractiveContext->Display(new AIS_Shape(aSequence->Value(i))); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
Handle(TopTools_HSequenceOfShape) CHuiStyleDoc::ReadIGES() { CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "IGES Files (*.iges , *.igs)|*.iges; *.igs|All Files (*.*)|*.*||", NULL ); TCHAR tchBuf[80]; CString CASROOTValue = ((GetEnvironmentVariable("CASROOT", tchBuf, 80) > 0) ? tchBuf : NULL); CString initdir = (CASROOTValue + "\\..\\data\\iges"); dlg.m_ofn.lpstrInitialDir = initdir; Handle(TopTools_HSequenceOfShape) aSequence = new TopTools_HSequenceOfShape(); if (dlg.DoModal() == IDOK) { SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)); CString C = dlg.GetPathName(); Standard_CString aFileName = (Standard_CString)(LPCTSTR)C; Standard_Integer status = ReadIGES(aFileName,aSequence); if (status != IFSelect_RetDone) { MessageBox(0,"Error : The file is not read","CasCade Error",MB_ICONERROR); } SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)); } return aSequence; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Standard_Integer CHuiStyleDoc::ReadIGES(const Standard_CString& aFileName, Handle(TopTools_HSequenceOfShape)& aHSequenceOfShape) { IGESControl_Reader Reader; Standard_Integer status = Reader.ReadFile(aFileName); if (status != IFSelect_RetDone) return status; Reader.TransferRoots(); TopoDS_Shape aShape = Reader.OneShape(); aHSequenceOfShape->Append(aShape); return status; } |
4. 添加 CColoredShapes 类
这个可以直接使用 x:\xxxx\opencascade-6.7.1\samples\mfc\standard\05_ImportExport\src 目录下的 ColoredShapes.h 和 ColoredShapes.cpp 文件,添加到项目中即可。但是你需要修改这些文件来适合你的需求,我直接使用的时候,发现它包含了很多其他头文件,并且级联包含其他,最后会弄出很多问题,所以这里我删去了很多,只保留我需要使用的,下面是我删减后的文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
// ColoredShape.h: interface for the CColoredShape class. // // #if !defined(AFX_COLOREDSHAPES_H__C6419AF3_A78A_11D1_8C93_00AA00D10994__INCLUDED_) #define AFX_COLOREDSHAPES_H__C6419AF3_A78A_11D1_8C93_00AA00D10994__INCLUDED_ #if _MSC_VER >= 1000 #pragma once #endif // _MSC_VER >= 1000 #include <TopTools_DataMapOfShapeInteger.hxx> class CColoredShapes : public CObject { public: CColoredShapes(); void Add(const Quantity_NameOfColor aColor, const TopoDS_Shape& aShape); void Remove(const TopoDS_Shape& aShape); void Display( Handle(AIS_InteractiveContext)& anAIScontext); TopoDS_ListOfShape getShapes(); Quantity_NameOfColor getShapeColor(TopoDS_Shape aShape); protected: // Declare CArchive >> operator DECLARE_SERIAL(CColoredShapes); private: TopTools_DataMapOfShapeInteger m_colorMap; TopoDS_ListOfShape m_shapeList; }; #endif // !defined(AFX_COLOREDSHAPES_H__C6419AF3_A78A_11D1_8C93_00AA00D10994__INCLUDED_) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
// ColoredShapes.cpp: implementation of the CColoredShape class. // // #include "stdafx.h" #include <afxtempl.h> #include "ColoredShapes.h" // // Construction/Destruction // CColoredShapes::CColoredShapes() { } void CColoredShapes::Add(const Quantity_NameOfColor aColor, const TopoDS_Shape& aShape) { m_shapeList.Clear(); m_shapeList.Append(aShape); m_colorMap.Bind(aShape, aColor); } void CColoredShapes::Remove(const TopoDS_Shape& aShape) { m_colorMap.UnBind(aShape); for ( TopoDS_ListIteratorOfListOfShape iter(m_shapeList); iter.More(); iter.Next() ) { if(iter.Value() == aShape) { m_shapeList.Remove(iter); break; } } } IMPLEMENT_SERIAL(CColoredShapes, CObject,1); // This schema contains all the Persistent Geometry and Topology #include <ShapeSchema.hxx> // Tools to store TopoDS_Shape #include <MgtBRep.hxx> #include <PTopoDS_HShape.hxx> #include <PTColStd_TransientPersistentMap.hxx> #include <TopoDS_Shape.hxx> // Tools to put Persistent Object in an archive #include <Storage_Data.hxx> #include <Storage_HSeqOfRoot.hxx> #include <Storage_Root.hxx> #include <PTColStd_PersistentTransientMap.hxx> void CColoredShapes::Display(Handle(AIS_InteractiveContext)& anAIScontext) { for ( TopoDS_ListIteratorOfListOfShape iter(m_shapeList); iter.More(); iter.Next() ) { Handle(AIS_Shape) ais = new AIS_Shape(iter.Value()); anAIScontext->SetColor(ais, (Quantity_NameOfColor)m_colorMap.Find(iter.Value())); anAIScontext->SetMaterial(ais, Graphic3d_NOM_GOLD, Standard_False); anAIScontext->Display(ais, Standard_False); } } |
5. 在Doc类中使用CColoredShapes对象
在 Doc类 中添加 成员变量:
1 2 |
protected: CColoredShapes* m_pcoloredshapeList; |
在 Doc类 的 初始化函数 中添加:
1 |
m_pcoloredshapeList = new CColoredShapes(); |
在 Doc类 的 析构函数 中添加:
1 |
if( m_pcoloredshapeList ) delete m_pcoloredshapeList; |
在 Doc类 的 Serialize 函数中添加:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
void CHuiStyleDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here ar << m_pcoloredshapeList; } else { // Read from the archive the current CColoredShape ar >> m_pcoloredshapeList; // Display the new object m_pcoloredshapeList->Display(myAISContext); } } |
在 OnImportIGES 函数中添加:
1 2 3 4 5 6 7 8 9 10 11 |
void CHuiStyleDoc::OnImportIGES() { // TODO: 在此添加命令处理程序代码 Handle(TopTools_HSequenceOfShape) aSeqOfShape = CHuiStyleDoc::ReadIGES(); for(int i=1;i<= aSeqOfShape->Length();i++) { m_pcoloredshapeList->Add(Quantity_NOC_YELLOW, aSeqOfShape->Value(i)); m_pcoloredshapeList->Display(myAISContext); } Fit(); } |
最后的 Fit函数 是用来调整显示的,调用 View类 中的 FitAll函数
1 2 3 4 5 6 |
void CHuiStyleDoc::Fit() { CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd; CHuiStyleView *pView = (CHuiStyleView *) pFrame->GetActiveView(); pView->FitAll(); } |
1 |
void FitAll() { if ( !myView.IsNull() ) myView->FitAll(); myView->ZFitAll(); }; |
至此,我们就可以载入 IGES 文件了,看下运行示例:
OpenCasCade – 载入IGES文件相关推荐
- OpenCASCADE:IGES 翻译器的介绍
OpenCASCADE:IGES 翻译器的介绍 IGES 接口读取 IGES 文件并将它们转换为 Open CASCADE Technology 模型.该界面能够翻译一个实体.一组实体或整个文件.在开 ...
- Keras学习笔记---保存model文件和载入model文件
Keras学习笔记---保存model文件和载入model文件 保存keras的model文件和载入keras文件的方法有很多.现在分别列出,以便后面查询. keras中的模型主要包括model和we ...
- Android执行时ART载入OAT文件的过程分析
在前面一文中,我们介绍了Android执行时ART,它的核心是OAT文件.OAT文件是一种Android私有ELF文件格式,它不仅包括有从DEX文件翻译而来的本地机器指令.还包括有原来的DEX文件内容 ...
- IGES文件解析1——几何图元(更新中...)
IGES文件解析1--几何图元 文件格式 开始段 全局段 数据索引段DE 数据参数PD 结束段 几何图元 圆弧(100型) 复合曲线(102型) 圆锥曲线(104型) 大量数据(类型 106) 平面( ...
- MATLAB type文件名,Matlab产生IGES文件代码
发现有人也在研究IGES文件格式,那就把之前编写的Matlab将数据写入IGES文件的代码上传吧,供大家参考.之前博客见 代码转载请注明作者. 代码如下,看看当初写的代码,好稚嫩啊 main脚本文件 ...
- 如何使用ansys将等高线txt文件转为iges文件
一.如何将等高线dxf文件获得dat文件 1.利用mapgis获得node文件 2.将node文件导入surfer8,XYZ坐标排序.克里格网格后可获得dat文件 二.如何将dat文件获得txt文件 ...
- 动态磁盘转回基本磁盘 | 警告你选定的操作会将基本磁盘转换为动态磁盘 | DiskGenius从镜像文件还原时,载入pmf文件,没有时间点
咱就是说要是早知道这是不可逆的操作,谁要点是呀 这篇回答,只能辨证来看,要是动态磁盘对你以后安装程序啥的没影响,你就不用转回基础盘了,如果你像我一样还是有顾虑,想转回去就接着看吧 方法一 :参考微软官 ...
- 如何在 C# 中以编程方式将 IGS/IGES 文件转换为 PDF?
计算机辅助设计应用程序使用 IGS 文件,因为它们包含设计信息.您可以将 IGS 文件转换为 PDF 格式的文档,以便在多个操作系统和环境中查看内容. 使用 C# 以编程方式将 IGS 或 IGES ...
- 植物大战僵尸 php,植物大战僵尸修改器使用方法 PHP __autoload函数(自动载入类文件)的使用方法...
这也是OO设计的基本思想之一.在PHP5之前,如果需要使用一个类,只需要直接使用include/require将其包含进来即可.下面是一个实际的例子: 复制代码 代码如下: class ClassA{ ...
- 基于opencascade的3D文件查看器Mayo开源工程使用QT编译配置
Mayo 是GitHub上一个基于opencascade的3D模型文件viewer开源项目,工程基于QT+opencascade,笔者出于对其界面的侧边栏感兴趣就尝试编译起来,就在这分享一下我的笔记. ...
最新文章
- Kubecon 2017大会Google高级产品经理David Aronchick访谈:机器学习和Kubernetes
- linux shell 判断字符串是否为数字
- java 锁竞争_Java多线程中的竞争条件、锁以及同步的概念
- python学习手册条件-总算晓得python学习手册正式版
- 记一次LAMP环境搭建
- 牛客 - 小V的序列(思维+位运算)
- liferay跳转页面
- oracle 修索引改空间_Oracle如何更改表空间的数据文件位置详解
- java长连接例子_java实现长连接
- jupyter(Anaconda)设置默认打开文件夹
- Nginx 简单命令
- printf 规定数据输出方式
- Android 系统应用Setting开发总结
- element el-select 支持拼音码和中文检索 检索的时候必须加属性 filterable
- Linux centOS系统备份还原(dd+rsync方式)
- 度过漫长又艰辛的 2020 年,我收集了 1273 人的年度感悟
- 概率论与数理统计 1 Overview and Descriptive Statistics(概述和描述性统计) (上篇)
- templets/default/index.htm Not Found! 图文教程 织梦程序的安装方法
- 【Web接口测试_基础概念】接口概念、接口分类、接口定义、接口规范、接口方法、接口用例设计整理
- MATLAB——求系统的零状态响应
热门文章
- hbase 使用lzo_【hbase】Hbase最佳实践
- python办公ppt_最全总结 | 聊聊 Python 办公自动化之 PPT(中)
- 51单片机怎么显示当前时间_历史曲线按照时间截取,并且显示波峰波谷值应该怎么做?...
- h5居中loading_H5样式与布局 --常用居中方法
- c 调用java map_如何从C中的map迭代器调用类成员函数?
- CMU 15-213 Introduction to Computer Systems学习笔记(17) Virtual Memory:System
- mysql没有开启binlog能恢复数据吗_【数据库】一个 rm -rf 把公司整个数据库删没了
- java 什么是精度_Java中BigDecimal精度和相等比较的坑
- iOS中的锁和线程同步
- Spring Mvc:用MultiPartFile上传单个文件,多个文件