当前位置: 首页 > news >正文

Open CASCADE学习|视图

目录

Mainwin.h

Mainwin.cpp


Mainwin.h

#pragma once#include <QtWidgets/QMainWindow>#include "Displaywin.h"#include "OCC.h"class Mainwin : public QMainWindow{  Q_OBJECTpublic:  Mainwin(QWidget* parent = nullptr);  ~Mainwin();private:  Mainwin* Mui;  Displaywin* Dui;private:  QMenu* fliemenuBar;  QAction* openstepfileaction;  QMenu* drawmenuBar;  QAction* drawboxaction;  QAction* drawbottleaction;  QAction* drawhelixaction;  QMenu* viewenuBar;  QAction* viewfrontaction;  QAction* viewbackaction;  QAction* viewtopaction;  QAction* viewbottomaction;  QAction* viewleftaction;  QAction* viewrightaction;  QAction* viewaxoaction;  QAction* viewresetaction;  QAction* viewfitallaction;  QAction* viewfitareaaction;  QAction* viewzoomaction;private:  void InitAction();  void InitMenu();private:  OCC occ;private slots:  void trigeropenfile();  void trigerdrawbox();  void trigerdrawbottle();  void trigerdrawhelix();  void trigerviewfront();  void trigerviewback();  void trigerviewtop();  void trigerviewbottom();  void trigerviewleft();  void trigerviewright();  void trigerviewaxo();  void trigerviewreset();  void trigerfitall();  void trigerfitarea();  void trigerzoom();};

Mainwin.cpp

#include "Mainwin.h"
#include<QMenu>
#include<QMenuBar>
#include <QMessageBox>
#include<QFileDialog>
Mainwin::Mainwin(QWidget* parent)
    : QMainWindow(parent)
{
    setWindowTitle(tr("my draw"));
    resize(500, 500);
​
    Dui = new Displaywin(this);
    setCentralWidget(Dui);
    InitAction();
    InitMenu();
}
Mainwin::~Mainwin()
{}
void Mainwin::InitAction()
{
    openstepfileaction = new QAction(tr("open"), this);
    openstepfileaction->setShortcut(tr("Ctrl+O"));
    openstepfileaction->setStatusTip(tr("open a step file"));
    connect(openstepfileaction, SIGNAL(triggered()), this, SLOT(trigeropenfile()));
​
    drawboxaction = new QAction(tr("box"), this);
    drawboxaction->setShortcut(tr("Ctrl+1"));
    drawboxaction->setStatusTip(tr("draw a box"));
    connect(drawboxaction, SIGNAL(triggered()), this, SLOT(trigerdrawbox()));
​
    drawbottleaction = new QAction(tr("bottle"), this);
    drawbottleaction->setShortcut(tr("Ctrl+2"));
    drawbottleaction->setStatusTip(tr("draw a bottle"));
    connect(drawbottleaction, SIGNAL(triggered()), this, SLOT(trigerdrawbottle()));
​
    drawhelixaction = new QAction(tr("helix"), this);
    drawhelixaction->setShortcut(tr("Ctrl+3"));
    drawhelixaction->setStatusTip(tr("draw a helix"));
    connect(drawhelixaction, SIGNAL(triggered()), this, SLOT(trigerdrawhelix()));
​
    viewfrontaction = new QAction(tr("front"), this);
    viewfrontaction->setShortcut(tr("Ctrl+4"));
    viewfrontaction->setStatusTip(tr("front"));
    connect(viewfrontaction, SIGNAL(triggered()), this, SLOT(trigerviewfront()));
​
    viewbackaction = new QAction(tr("back"), this);
    viewbackaction->setShortcut(tr("Ctrl+5"));
    viewbackaction->setStatusTip(tr("back"));
    connect(viewbackaction, SIGNAL(triggered()), this, SLOT(trigerviewback()));
​
    viewtopaction = new QAction(tr("top"), this);
    viewtopaction->setShortcut(tr("Ctrl+6"));
    viewtopaction->setStatusTip(tr("top"));
    connect(viewtopaction, SIGNAL(triggered()), this, SLOT(trigerviewtop()));
​
    viewbottomaction = new QAction(tr("bottom"), this);
    viewbottomaction->setShortcut(tr("Ctrl+7"));
    viewbottomaction->setStatusTip(tr("bottom"));
    connect(viewbottomaction, SIGNAL(triggered()), this, SLOT(trigerviewbottom()));
​
    viewleftaction = new QAction(tr("left"), this);
    viewleftaction->setShortcut(tr("Ctrl+8"));
    viewleftaction->setStatusTip(tr("left"));
    connect(viewleftaction, SIGNAL(triggered()), this, SLOT(trigerviewleft()));
​
    viewrightaction = new QAction(tr("right"), this);
    viewrightaction->setShortcut(tr("Ctrl+9"));
    viewrightaction->setStatusTip(tr("right"));
    connect(viewrightaction, SIGNAL(triggered()), this, SLOT(trigerviewright()));
​
    viewaxoaction = new QAction(tr("axo"), this);
    viewaxoaction->setShortcut(tr("Ctrl+A"));
    viewaxoaction->setStatusTip(tr("axo"));
    connect(viewaxoaction, SIGNAL(triggered()), this, SLOT(trigerviewaxo()));
​
    viewresetaction = new QAction(tr("reset"), this);
    viewresetaction->setShortcut(tr("Ctrl+B"));
    viewresetaction->setStatusTip(tr("reset"));
    connect(viewresetaction, SIGNAL(triggered()), this, SLOT(trigerviewreset()));
​
    viewfitallaction = new QAction(tr("fitall"), this);
    viewfitallaction->setShortcut(tr("Ctrl+C"));
    viewfitallaction->setStatusTip(tr("fitall"));
    connect(viewfitallaction, SIGNAL(triggered()), this, SLOT(trigerfitall()));
​
    viewfitareaaction = new QAction(tr("fitarea"), this);
    viewfitareaaction->setShortcut(tr("Ctrl+D"));
    viewfitareaaction->setStatusTip(tr("fitarea"));
    connect(viewfitareaaction, SIGNAL(triggered()), this, SLOT(trigerfitarea()));
​
    viewzoomaction = new QAction(tr("zoom"), this);
    viewzoomaction->setShortcut(tr("Ctrl+E"));
    viewzoomaction->setStatusTip(tr("zoom"));
    connect(viewzoomaction, SIGNAL(triggered()), this, SLOT(trigerzoom()));
}
​
void Mainwin::InitMenu()
{
    fliemenuBar = menuBar()->addMenu("Flie");
    fliemenuBar->addAction(openstepfileaction);
​
​
    drawmenuBar = menuBar()->addMenu("Draw");
    drawmenuBar->addAction(drawboxaction);
    drawmenuBar->addAction(drawbottleaction);
    drawmenuBar->addAction(drawhelixaction);
​
    viewenuBar = menuBar()->addMenu("View");
    viewenuBar->addAction(viewfrontaction);
    viewenuBar->addAction(viewbackaction);
    viewenuBar->addAction(viewtopaction);
    viewenuBar->addAction(viewbottomaction);
    viewenuBar->addAction(viewleftaction);
    viewenuBar->addAction(viewrightaction);
    viewenuBar->addAction(viewaxoaction);
    viewenuBar->addAction(viewresetaction);
    viewenuBar->addAction(viewfitallaction);
    viewenuBar->addAction(viewfitareaaction);
    viewenuBar->addAction(viewzoomaction);
​
}
void Mainwin::trigeropenfile()
{
​
    QString filename = QFileDialog::getOpenFileName(this, "open file dialog", "/", "step files(*.step)");
    std::string stdfilename = filename.toStdString();
    const char* cstr = stdfilename.c_str();
    TopoDS_Shape stepShape = occ.Open_STEP(cstr);
    Quantity_Color color = Quantity_Color(0.3, 0.5, 0.3, Quantity_TOC_RGB);
    Handle(AIS_Shape) aisstep = new AIS_Shape(stepShape);
    Dui->GetInteractiveContext()->Display(aisstep, Standard_True);
    Dui->GetView()->FitAll();
​
}
​
void Mainwin::trigerdrawbox()
{
    TopoDS_Shape box = occ.createBox();
    Handle(AIS_Shape) aisBox = new AIS_Shape(box);
    Dui->GetInteractiveContext()->Display(aisBox, Standard_True);
    Dui->GetView()->FitAll();
​
}
void Mainwin::trigerdrawbottle()
{
    TopoDS_Shape bottle = occ.MakeBottle(50, 70, 30);
    Handle(AIS_Shape) aisBottle = new AIS_Shape(bottle);
    Dui->GetInteractiveContext()->Display(aisBottle, Standard_True);
    Dui->GetView()->FitAll();
}
void Mainwin::trigerdrawhelix()
{
    TopoDS_Shape helix = occ.createHelix2(3.0, M_PI/3,3.63);
    Handle(AIS_Shape) aishelix = new AIS_Shape(helix);
    Dui->GetInteractiveContext()->Display(aishelix, Standard_True);
    Dui->GetView()->FitAll();
}
void Mainwin::trigerviewfront()
{
    Dui->GetView()->SetProj(V3d_Yneg);
}
​
void Mainwin::trigerviewback()
{
    Dui->GetView()->SetProj(V3d_Ypos);
}
​
void Mainwin::trigerviewtop()
{
    Dui->GetView()->SetProj(V3d_Zpos);
}
​
void Mainwin::trigerviewbottom()
{
    Dui->GetView()->SetProj(V3d_Zneg);
}
​
void Mainwin::trigerviewleft()
{
    Dui->GetView()->SetProj(V3d_Xneg);
}
​
void Mainwin::trigerviewright()
{
    Dui->GetView()->SetProj(V3d_Xpos);
}
​
void Mainwin::trigerviewaxo()
{
    Dui->GetView()->SetProj(V3d_XposYnegZpos);
}
​
void Mainwin::trigerviewreset()
{
    Dui->GetView()->Reset();
}
void Mainwin::trigerfitall()
{
    Dui->GetView()->FitAll();
    Dui->GetView()->ZFitAll();
    Dui->GetView()->Redraw();
}
​
void Mainwin::trigerfitarea()
{
    //setCurrentAction(CurAction3d_WindowZooming);
}
​
void Mainwin::trigerzoom()
{
    //setCurrentAction(CurAction3d_DynamicZooming);
}

相关文章:

  • Python零基础安装教程(包含各种安装方案)以及PyCharm安装步骤
  • 第七章 正则表达式
  • 机器人内部传感器阅读笔记及心得-位置传感器-旋转变压器、激光干涉式编码器
  • C++多态
  • 理想滤波器、巴特沃斯滤波器、高斯滤波器实现(包含低通与高通,代码实现与分析)
  • opengl播放3d pose 原地舞蹈脚来回飘动
  • C++拿几道题练练手吧
  • java面试题之mybatis篇
  • 浅谈 TCP 三次握手
  • 【牛客】SQL123 SQL类别高难度试卷得分的截断平均值
  • 支持国密ssl的curl编译和测试验证(下)
  • 什么是高可用架构
  • 代码随想录|学习工具分享
  • Spring Boot自动装配原理
  • 【LeetCode】【滑动窗口长度不固定】978 最长湍流子数组
  • 合并spark structured streaming处理流式数据产生的小文件
  • 多模态表征—CLIP及中文版Chinese-CLIP:理论讲解、代码微调与论文阅读
  • 使用React和ResizeObserver实现自适应ECharts图表
  • prometheus监控带安全认证的elasticsearch
  • docker创建mongodb数据库容器
  • 人社部:对个人加大就业补贴支持,对企业加大扩岗支持
  • “中国游”带火“中国购”,“即买即退”让外国游客购物更丝滑
  • 影子调查丨起底“三无”拖拉机产销链:出口掩内销,监管如虚设
  • 同款瑞幸咖啡竟差了6元,开了会员仍比别人贵!客服回应
  • 持续更新丨伊朗内政部长:港口爆炸已致14人死亡
  • 艺术与医学的对话,瑞金医院办了一个展览