FreeCAD源码分析:FreeCADGui模块

FreeCAD源码分析:FreeCADGui模块
FreeCAD源码分析:FreeCADGui模块
济南友泉软件有限公司
FreeCADGui项⽬实现了界⾯操作、模型显⽰与交互等相关功能,项⽬构建⽣成FreeCAD(_d).dll动态链接库。
FreeCADGuiPy项⽬在FreeCADGui基础之上,构建⽣成FreeCADGui(_d).pyd,实现对Python中“import FreeCADGui”语句的⽀持。
FreeCADGuiPy⽐较简单,因此,本⽂主要针对FreeCADGui进⾏分析。
⼀、模块功能概述
FreeCADGui模块基于⽂档-视图架构实现了多⽂档CAD软件开发的框架。不仅提供了基于Workbench的界⾯管理,⽽且提供了⼤量的⽤于完成数据对象渲染的视图。主要功能包括:
Workbench管理
ras同步适配器
Workbench实际上针对特定应⽤的⼯具及其界⾯显⽰。FreeCAD提供了拓展性较强的基于Workbench的软件开发思路,可以通过Workbench 定义软件的外观及其具体的功能。
停靠窗⼝管理
停靠窗⼝实际上是窗⼝部件的容器,可以将内嵌的窗⼝部件显⽰在主窗⼝的四周,也可以悬浮在桌⾯。
命令管理
Workbench由根据具体问题定义的命令⼯具集来实现,FreeCAD提供了CommandMnanger⽤于完成对Command及其⼦类的管理。
菜单管理
菜单(包括⼯具按钮)实际上是不分命令集的界⾯表现,通过关联Qmenu与QAction将全部或者部分命令集显⽰出来,同时建⽴界⾯操作与命令响应之间的关联。
视图显⽰
视图⽤于显⽰⽂档对象数据,同时可以将⽤户界⾯输⼊转换成数据对象操作。基于BaseView、MDIView及其⼦类,实现了⽂档-视图架构,可⽤于在界⾯窗⼝中显⽰数据对象。
属性系统
基于Qt Model-View架构,实现数据对象显⽰、编辑与Qt部件的关联。
⼆、Gui::Appication
Gui::Application提供了多⽂档应⽤程序开发的框架,⽀持⽂档操作、模块管理、软件启动等相关服务,其内部ApplicationP类型对象维护了⽂档列表、视图列表、命令管理器、宏管理器等相关数据对象。
struct ApplicationP
{
ApplicationP() :
activeDocument(0L),
isClosing(false),
startingUp(true)
{
// create the macro manager
macroMngr = new MacroManager();
}
~ApplicationP()
自组网电台{
delete macroMngr;
}
/// list of all handled documents
std::map<const App::Document*, Gui::Document*> documents;
/// Active document
Gui::Document*  activeDocument;
MacroManager*  macroMngr;
/// List of all registered views
std::list<Gui::BaseView*> passive;
bool isClosing;
bool startingUp;
背心袋生产设备/// Handles all commands
CommandManager commandManager;
};
存在全局唯⼀的⼀个Application对象,
static Application* Application::Instance;
FreeCAD启动时,会通过Application定义的若⼲静态成员函数完成配置加载、初始化、模块加载、创建界⾯窗⼝等⼯作。
static void Application::initApplication(void);
static void Application::initTypes(void);
static void Application::initOpenInventor(void);
static void Application::runInitGuiScript(void);
static void Application::runApplication(void);
三、主窗⼝
Gui::MainWindow是FreeCAD在QMainWindow的基础之上提供的主窗⼝,该类提供了⼦窗⼝管理、弹出菜单、事件处理等功能。
存在全局唯⼀的Gui::MainWindow对象instance,
static MainWindow* MainWindow::instance;
static MainWindow* MainWindow::getInstance();
Gui::MainWindow属性存储在MainWindowP类型的结构体中,
透风窗struct MainWindow::MainWindowP* d;
struct MainWindowP
{
QLabel* sizeLabel;
QLabel* actionLabel;
QTimer* actionTimer;
QTimer* activityTimer;
QTimer* visibleTimer;
QMdiArea* mdiArea;
QPointer<MDIView> activeView;
QSignalMapper* windowMapper;
QSplashScreen* splashscreen;
StatusBarObserver* status;
bool whatsthis;
QString whatstext;
Assistant* assistant;
QMap<QString, QPointer<UrlHandler> > urlHandler;
};
变量名类型描述
sizeLabel QLabel*显⽰当前视图的⼏何维度actionLabel QLabel*显⽰操作信息actionTimer QTimer*在状态栏显⽰操作信息5秒
activityTimer QTimer*每300毫秒触发⼀次,更新界⾯命令的显⽰
普通注塑机射咀头
visibleTimer QTimer*主窗⼝MainWindow显⽰定时器
mdiArea QMdiArea*多⽂档窗⼝显⽰的区域
activeView QPointer<MDIView>同⼀时刻,最多只有⼀个视图作为当前视图并处于激活状态
windowMapper QSignalMapper*信号映射器,splashscreen QSplashScreen*FreeCAD启动时的欢迎界⾯
status StatusBarObserver*监控控制台输出,通
过CustomMessageEvent类型事件将消息(⿊⾊)、警告(黄⾊)、错误(红⾊)输出到状态栏。
whatsthis bool是否显⽰帮助提⽰信息
微服务开发(What’s This)
whatstext QString 帮助提⽰信息(What’s This)
assistant Assistant*调⽤ Qt assistant显⽰FreeCAD⽂档
urlHandler QMap<QString,
QPointer<UrlHandler>
>
加载Url资源
3.1 欢迎界⾯
SplashScreen类不仅提供了⾃动加载欢迎界⾯,⽽且通过监控控制台输出以显⽰模块的加载进度。
MainWindow在FreeCAD启动的时候,会弹出欢迎界⾯窗⼝。Gui::MainWindow提供了以下两个函数完成欢迎界⾯窗⼝的创建与销毁。
void MainWindow::startSplasher(void);
void MainWindow::stopSplasher(void);
QPixmap MainWindow::splashImage() const;
实际上,这两个函数调⽤发⽣在void Application::runApplication(void)。可以在FreeCADMain MainGui.cpp中配置欢迎界⾯,
App::Application::Config()["SplashScreen"] = "freecadsplash";
App::Application::Config()["SplashAlignment" ] = "Bottom|Left";
App::Application::Config()["SplashTextColor" ] = "#ffffff"; // white
App::Application::Config()["SplashInfoColor" ] = "#c8c8c8"; // light grey
其中图像资源”freecadsplash”在FreeCADGui resource.qrc中进⾏了定义。
3.2 命令管理
CommandManager管理所有注册的Command及其派⽣类型对象,通过将Command与QAction相关联,可以将界⾯操作转换成Command对象的命令响应。
通常在界⾯模块⽂件中,利⽤CommandManager完成相关命令对象的注册。例如,对于CfdGui模块,在其AppCfdGui.cpp中,
// use a different name to CreateCommand()
void CreateCfdCommands(void);
//void loadStartResource()
//{
//    // add resources and reloads the translators
//    Q_INIT_RESOURCE(Cfd);
//    Gui::Translator::instance()->refresh();
//}

本文发布于:2024-09-20 20:36:15,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/3/98015.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:对象   视图   命令   模块
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议