Sketcher: New toolbar for VirtualSpace and Command to switch VirtualSpace
This commit is contained in:
@@ -50,6 +50,7 @@ void CreateSketcherCommandsConstraints(void);
|
||||
void CreateSketcherCommandsConstraintAccel(void);
|
||||
void CreateSketcherCommandsAlterGeo(void);
|
||||
void CreateSketcherCommandsBSpline(void);
|
||||
void CreateSketcherCommandsVirtualSpace(void);
|
||||
|
||||
void loadSketcherResource()
|
||||
{
|
||||
@@ -106,6 +107,7 @@ PyMOD_INIT_FUNC(SketcherGui)
|
||||
CreateSketcherCommandsAlterGeo();
|
||||
CreateSketcherCommandsConstraintAccel();
|
||||
CreateSketcherCommandsBSpline();
|
||||
CreateSketcherCommandsVirtualSpace();
|
||||
|
||||
SketcherGui::Workbench::init();
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ SET(SketcherGui_SRCS
|
||||
CommandConstraints.cpp
|
||||
CommandSketcherTools.cpp
|
||||
CommandSketcherBSpline.cpp
|
||||
CommandSketcherVirtualSpace.cpp
|
||||
CommandAlterGeometry.cpp
|
||||
Resources/Sketcher.qrc
|
||||
PreCompiled.cpp
|
||||
|
||||
130
src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp
Normal file
130
src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2017 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <cfloat>
|
||||
# include <QMessageBox>
|
||||
# include <Precision.hxx>
|
||||
# include <QApplication>
|
||||
# include <Standard_Version.hxx>
|
||||
#endif
|
||||
|
||||
# include <QMessageBox>
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <App/Application.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/DlgEditFileIncludeProptertyExternal.h>
|
||||
|
||||
#include <Gui/Action.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
|
||||
#include "ViewProviderSketch.h"
|
||||
#include "DrawSketchHandler.h"
|
||||
|
||||
#include <Mod/Part/App/Geometry.h>
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
|
||||
#include "CommandConstraints.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace SketcherGui;
|
||||
using namespace Sketcher;
|
||||
|
||||
bool isSketcherVirtualSpaceActive(Gui::Document *doc, bool actsOnSelection )
|
||||
{
|
||||
if (doc) {
|
||||
// checks if a Sketch Viewprovider is in Edit and is in no special mode
|
||||
if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) {
|
||||
if (static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit())
|
||||
->getSketchMode() == ViewProviderSketch::STATUS_NONE) {
|
||||
if (!actsOnSelection)
|
||||
return true;
|
||||
else if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ActivateVirtualSpaceHandler(Gui::Document *doc,DrawSketchHandler *handler)
|
||||
{
|
||||
if (doc) {
|
||||
if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom
|
||||
(SketcherGui::ViewProviderSketch::getClassTypeId())) {
|
||||
|
||||
SketcherGui::ViewProviderSketch* vp = static_cast<SketcherGui::ViewProviderSketch*> (doc->getInEdit());
|
||||
vp->purgeHandler();
|
||||
vp->activateHandler(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Show/Hide B-spline degree
|
||||
DEF_STD_CMD_A(CmdSketcherSwitchVirtualSpace);
|
||||
|
||||
CmdSketcherSwitchVirtualSpace::CmdSketcherSwitchVirtualSpace()
|
||||
:Command("Sketcher_SwitchVirtualSpace")
|
||||
{
|
||||
sAppModule = "Sketcher";
|
||||
sGroup = QT_TR_NOOP("Sketcher");
|
||||
sMenuText = QT_TR_NOOP("Switch virtual space");
|
||||
sToolTipText = QT_TR_NOOP("Switches between the two virtual spaces");
|
||||
sWhatsThis = "Sketcher_SwitchVirtualSpace";
|
||||
sStatusTip = sToolTipText;
|
||||
sPixmap = "Sketcher_SwitchVirtualSpace";
|
||||
sAccel = "";
|
||||
eType = ForEdit;
|
||||
}
|
||||
|
||||
void CmdSketcherSwitchVirtualSpace::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
|
||||
Gui::Document * doc= getActiveGuiDocument();
|
||||
|
||||
SketcherGui::ViewProviderSketch* vp = static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
|
||||
|
||||
vp->setIsShownVirtualSpace(!vp->getIsShownVirtualSpace());
|
||||
|
||||
}
|
||||
|
||||
bool CmdSketcherSwitchVirtualSpace::isActive(void)
|
||||
{
|
||||
return isSketcherVirtualSpaceActive( getActiveGuiDocument(), false );
|
||||
}
|
||||
|
||||
|
||||
void CreateSketcherCommandsVirtualSpace(void)
|
||||
{
|
||||
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
|
||||
|
||||
rcCmdMgr.addCommand(new CmdSketcherSwitchVirtualSpace());
|
||||
}
|
||||
@@ -83,12 +83,17 @@ Gui::MenuItem* Workbench::setupMenuBar() const
|
||||
Gui::MenuItem* bsplines = new Gui::MenuItem();
|
||||
bsplines->setCommand("Sketcher B-spline tools");
|
||||
addSketcherWorkbenchBSplines(*bsplines);
|
||||
|
||||
Gui::MenuItem* virtualspace = new Gui::MenuItem();
|
||||
virtualspace->setCommand("Sketcher Virtual Space");
|
||||
addSketcherWorkbenchVirtualSpace(*virtualspace);
|
||||
|
||||
addSketcherWorkbenchSketchActions( *sketch );
|
||||
*sketch << geom
|
||||
<< cons
|
||||
<< consaccel
|
||||
<< bsplines;
|
||||
<< bsplines
|
||||
<< virtualspace;
|
||||
|
||||
return root;
|
||||
}
|
||||
@@ -116,6 +121,10 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
|
||||
Gui::ToolBarItem* bspline = new Gui::ToolBarItem(root);
|
||||
bspline->setCommand("Sketcher B-spline tools");
|
||||
addSketcherWorkbenchBSplines( *bspline );
|
||||
|
||||
Gui::ToolBarItem* virtualspace = new Gui::ToolBarItem(root);
|
||||
bspline->setCommand("Sketcher Virtual Space tools");
|
||||
addSketcherWorkbenchVirtualSpace( *virtualspace );
|
||||
|
||||
return root;
|
||||
}
|
||||
@@ -306,6 +315,19 @@ inline void SketcherAddWorkbenchBSplines<Gui::ToolBarItem>(Gui::ToolBarItem& bsp
|
||||
<< "Sketcher_CompModifyKnotMultiplicity";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void SketcherAddWorkbenchVirtualSpace(T& virtualspace);
|
||||
|
||||
template <>
|
||||
inline void SketcherAddWorkbenchVirtualSpace<Gui::MenuItem>(Gui::MenuItem& virtualspace){
|
||||
virtualspace << "Sketcher_SwitchVirtualSpace";
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void SketcherAddWorkbenchVirtualSpace<Gui::ToolBarItem>(Gui::ToolBarItem& virtualspace){
|
||||
virtualspace << "Sketcher_SwitchVirtualSpace";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void SketcherAddWorkspaceSketchExtra(T& /*sketch*/){
|
||||
}
|
||||
@@ -342,6 +364,10 @@ void addSketcherWorkbenchBSplines( Gui::MenuItem& bspline ){
|
||||
SketcherAddWorkbenchBSplines( bspline );
|
||||
}
|
||||
|
||||
void addSketcherWorkbenchVirtualSpace( Gui::MenuItem& virtualspace ){
|
||||
SketcherAddWorkbenchVirtualSpace( virtualspace );
|
||||
}
|
||||
|
||||
void addSketcherWorkbenchSketchActions( Gui::MenuItem& sketch ){
|
||||
Sketcher_addWorkbenchSketchActions( sketch );
|
||||
}
|
||||
@@ -363,6 +389,11 @@ void addSketcherWorkbenchBSplines( Gui::ToolBarItem& bspline )
|
||||
SketcherAddWorkbenchBSplines( bspline );
|
||||
}
|
||||
|
||||
void addSketcherWorkbenchVirtualSpace( Gui::ToolBarItem& virtualspace )
|
||||
{
|
||||
SketcherAddWorkbenchVirtualSpace( virtualspace );
|
||||
}
|
||||
|
||||
void addSketcherWorkbenchSketchActions( Gui::ToolBarItem& sketch ){
|
||||
Sketcher_addWorkbenchSketchActions( sketch );
|
||||
}
|
||||
|
||||
@@ -53,12 +53,14 @@ protected:
|
||||
SketcherGuiExport void addSketcherWorkbenchConstraints( Gui::MenuItem& cons );
|
||||
SketcherGuiExport void addSketcherWorkbenchTools( Gui::MenuItem& consaccel );
|
||||
SketcherGuiExport void addSketcherWorkbenchBSplines( Gui::MenuItem& bspline );
|
||||
SketcherGuiExport void addSketcherWorkbenchVirtualSpace( Gui::MenuItem& virtualspace );
|
||||
SketcherGuiExport void addSketcherWorkbenchSketchActions( Gui::MenuItem& sketch );
|
||||
SketcherGuiExport void addSketcherWorkbenchGeometries( Gui::MenuItem& geom );
|
||||
|
||||
SketcherGuiExport void addSketcherWorkbenchConstraints( Gui::ToolBarItem& cons );
|
||||
SketcherGuiExport void addSketcherWorkbenchTools( Gui::ToolBarItem& consaccel );
|
||||
SketcherGuiExport void addSketcherWorkbenchBSplines( Gui::ToolBarItem& bspline );
|
||||
SketcherGuiExport void addSketcherWorkbenchVirtualSpace( Gui::ToolBarItem& virtualspace );
|
||||
SketcherGuiExport void addSketcherWorkbenchSketchActions( Gui::ToolBarItem& sketch );
|
||||
SketcherGuiExport void addSketcherWorkbenchGeometries( Gui::ToolBarItem& geom );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user