From 5a40cd0ae503fa186f763f1b6b28d9b5994c933d Mon Sep 17 00:00:00 2001 From: Wanderer Fan Date: Tue, 18 Jan 2022 10:21:19 -0500 Subject: [PATCH] [TD]Add MoveView and CopyView commands --- src/Mod/TechDraw/CMakeLists.txt | 30 +- src/Mod/TechDraw/Gui/CMakeLists.txt | 5 + src/Mod/TechDraw/Gui/DlgPageChooser.ui | 2 +- src/Mod/TechDraw/Gui/Resources/TechDraw.qrc | 2 + .../icons/actions/TechDraw_CopyView.svg | 641 ++++++++++++++++++ .../icons/actions/TechDraw_MoveView.svg | 630 +++++++++++++++++ src/Mod/TechDraw/Gui/TaskMoveView.ui | 101 +++ src/Mod/TechDraw/Gui/Workbench.cpp | 8 + src/Mod/TechDraw/InitGui.py | 6 + .../TechDraw/TechDrawTools/CommandCopyView.py | 90 +++ .../TechDraw/TechDrawTools/CommandMoveView.py | 89 +++ .../TechDraw/TechDrawTools/TDToolsMovers.py | 73 ++ src/Mod/TechDraw/TechDrawTools/TDToolsUtil.py | 38 ++ .../TechDraw/TechDrawTools/TaskCopyView.py | 133 ++++ .../TechDraw/TechDrawTools/TaskMoveView.py | 134 ++++ src/Mod/TechDraw/TechDrawTools/__init__.py | 38 ++ 16 files changed, 2018 insertions(+), 2 deletions(-) create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_CopyView.svg create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_MoveView.svg create mode 100644 src/Mod/TechDraw/Gui/TaskMoveView.ui create mode 100644 src/Mod/TechDraw/TechDrawTools/CommandCopyView.py create mode 100644 src/Mod/TechDraw/TechDrawTools/CommandMoveView.py create mode 100644 src/Mod/TechDraw/TechDrawTools/TDToolsMovers.py create mode 100644 src/Mod/TechDraw/TechDrawTools/TDToolsUtil.py create mode 100644 src/Mod/TechDraw/TechDrawTools/TaskCopyView.py create mode 100644 src/Mod/TechDraw/TechDrawTools/TaskMoveView.py create mode 100644 src/Mod/TechDraw/TechDrawTools/__init__.py diff --git a/src/Mod/TechDraw/CMakeLists.txt b/src/Mod/TechDraw/CMakeLists.txt index 2a4c8c3a86..ed51245705 100644 --- a/src/Mod/TechDraw/CMakeLists.txt +++ b/src/Mod/TechDraw/CMakeLists.txt @@ -11,6 +11,21 @@ set(TechDraw_Scripts TestTechDrawApp.py ) +if(BUILD_GUI) + list (APPEND Image_Scripts InitGui.py) + set(TechDraw_ToolsScripts + TechDrawTools/__init__.py + TechDrawTools/CommandMoveView.py + TechDrawTools/CommandCopyView.py + TechDrawTools/TaskMoveView.py + TechDrawTools/TaskCopyView.py + TechDrawTools/TDToolsUtil.py + TechDrawTools/TDToolsMovers.py + Gui/TaskMoveView.ui + Gui/DlgPageChooser.ui + ) +endif(BUILD_GUI) + if(BUILD_GUI) list (APPEND TechDraw_Scripts InitGui.py) endif(BUILD_GUI) @@ -24,7 +39,7 @@ SET(TechDraw_LineGroupFile ) add_custom_target(TechDraw_Data ALL -SOURCES ${TechDraw_Scripts} ${TechDraw_PATFile} ${TechDraw_LineGroupFile} +SOURCES ${TechDraw_Scripts} ${TechDraw_PATFile} ${TechDraw_LineGroupFile} ${TechDraw_ToolsScripts} ) fc_target_copy_resource(TechDraw_Data @@ -43,6 +58,12 @@ fc_target_copy_resource(TechDraw_Data ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/TechDraw ${TechDraw_LineGroupFile}) +fc_target_copy_resource(TechDraw_Data + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_BINARY_DIR}/Mod/TechDraw + ${TechDraw_ToolsScripts} +) + INSTALL( FILES ${TechDraw_Scripts} @@ -50,6 +71,13 @@ INSTALL( Mod/TechDraw ) +INSTALL( + FILES + ${TechDraw_ToolsScripts} + DESTINATION + Mod/TechDraw/TechDrawTools +) + INSTALL( DIRECTORY Templates diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 59ed6c6c49..418720d2b9 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -83,6 +83,8 @@ set(TechDrawGui_UIC_SRCS TaskSectionView.ui TaskWeldingSymbol.ui SymbolChooser.ui + TaskMoveView.ui + ) if(BUILD_QT5) @@ -207,6 +209,7 @@ SET(TechDrawGui_SRCS TaskCosmeticLine.ui TaskCosmeticLine.cpp TaskCosmeticLine.h + TaskMoveView.ui ) SET(TechDrawGuiView_SRCS @@ -377,6 +380,8 @@ SET(TechDrawGuiTaskDlgs_SRCS TaskDetail.ui TaskCosmeticLine.ui TaskSelectLineAttributes.ui + TaskMoveView.ui + ) SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS}) diff --git a/src/Mod/TechDraw/Gui/DlgPageChooser.ui b/src/Mod/TechDraw/Gui/DlgPageChooser.ui index c10bdf4304..755c037882 100644 --- a/src/Mod/TechDraw/Gui/DlgPageChooser.ui +++ b/src/Mod/TechDraw/Gui/DlgPageChooser.ui @@ -24,7 +24,7 @@ - + FreeCAD could not determine which Page to use. Please select a Page. diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index da0b03cc32..ea7f5442d8 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -109,6 +109,8 @@ icons/actions/TechDraw_Symbol.svg icons/actions/TechDraw_Tile.svg icons/actions/TechDraw_WeldSymbol.svg + icons/actions/TechDraw_MoveView.svg + icons/actions/TechDraw_CopyView.svg icons/actions/section-up.svg icons/actions/section-down.svg icons/actions/section-left.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_CopyView.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_CopyView.svg new file mode 100644 index 0000000000..0451f24034 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_CopyView.svg @@ -0,0 +1,641 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + [agryson] Alexander Gryson + + + http://agryson.net + + techdraw-view + 2016-01-14 + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + FreeCAD + + + FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-view.svg + + + FreeCAD LGPL2+ + + + + + [agryson] Alexander Gryson + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_MoveView.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_MoveView.svg new file mode 100644 index 0000000000..6c11f9efab --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/TechDraw_MoveView.svg @@ -0,0 +1,630 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + [agryson] Alexander Gryson + + + http://agryson.net + + techdraw-view + 2016-01-14 + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + FreeCAD + + + FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-view.svg + + + FreeCAD LGPL2+ + + + + + [agryson] Alexander Gryson + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/TaskMoveView.ui b/src/Mod/TechDraw/Gui/TaskMoveView.ui new file mode 100644 index 0000000000..3ec255a504 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskMoveView.ui @@ -0,0 +1,101 @@ + + + TaskMoveView + + + + 0 + 0 + 400 + 159 + + + + Move View + + + + + + + + ... + + + + + + + ... + + + + + + + true + + + + + + + ... + + + + + + + true + + + + + + + true + + + + + + + From Page + + + + + + + To Page + + + + + + + View to move + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index 4541a8bc8b..a8f30b2928 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -184,6 +184,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_ClipGroupAdd"; *draw << "TechDraw_ClipGroupRemove"; *draw << "Separator"; + *draw << "TechDraw_MoveView"; + *draw << "TechDraw_CopyView"; *draw << dimensions; *draw << toolattrib; *draw << toolcenter; @@ -227,6 +229,9 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *views << "TechDraw_DraftView"; *views << "TechDraw_ArchView"; *views << "TechDraw_SpreadsheetView"; + *views << "TechDraw_MoveView"; + *views << "TechDraw_CopyView"; + Gui::ToolBarItem *clips = new Gui::ToolBarItem(root); clips->setCommand("TechDraw Clips"); @@ -358,6 +363,9 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *views << "TechDraw_DetailView"; *views << "TechDraw_DraftView"; *views << "TechDraw_SpreadsheetView"; + *views << "TechDraw_MoveView"; + *views << "TechDraw_CopyView"; + Gui::ToolBarItem *clips = new Gui::ToolBarItem(root); clips->setCommand("TechDraw Clips"); diff --git a/src/Mod/TechDraw/InitGui.py b/src/Mod/TechDraw/InitGui.py index a57eb1b2fc..9c4fe8b936 100644 --- a/src/Mod/TechDraw/InitGui.py +++ b/src/Mod/TechDraw/InitGui.py @@ -39,6 +39,12 @@ class TechDrawWorkbench (Workbench): def Initialize(self): # load the module import TechDrawGui + + try: + import TechDrawTools + except ImportError as err: + FreeCAD.Console.PrintError("Features from TechDrawTools package cannot be loaded. {err}\n".format(err= str(err))) + def GetClassName(self): return "TechDrawGui::Workbench" diff --git a/src/Mod/TechDraw/TechDrawTools/CommandCopyView.py b/src/Mod/TechDraw/TechDrawTools/CommandCopyView.py new file mode 100644 index 0000000000..6743c81f77 --- /dev/null +++ b/src/Mod/TechDraw/TechDrawTools/CommandCopyView.py @@ -0,0 +1,90 @@ +# *************************************************************************** +# * Copyright (c) 2022 Wanderer Fan * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program 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 program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** +"""Provides the TechDraw CopyView GuiCommand.""" + +__title__ = "TechDrawTools.CommandCopyView" +__author__ = "WandererFan" +__url__ = "http://www.freecadweb.org/index.html" +__version__ = "00.01" +__date__ = "2022/01/11" + +from PySide.QtCore import QT_TRANSLATE_NOOP + +import FreeCAD as App +import FreeCADGui as Gui + +import TechDrawTools + +class CommandCopyView: + """Copies a View from current Page to a different Page.""" + + def __init__(self): + """Initialize variables for the command that must exist at all times.""" + pass + + def GetResources(self): + """Return a dictionary with data that will be used by the button or menu item.""" + return {'Pixmap': 'actions/TechDraw_CopyView.svg', + 'Accel': "", + 'MenuText': QT_TRANSLATE_NOOP("CopyView", "Copy View"), + 'ToolTip': QT_TRANSLATE_NOOP("CopyView", "Copy a View to a second Page")} + + def Activated(self): + """Run the following code when the command is activated (button press).""" +# print("Activated()") + sel = Gui.Selection.getSelection() + + vName = "" + views = list() + for o in sel: + if o.isDerivedFrom("TechDraw::DrawView"): + views.append(o) + if views: + vName = views[0].Name + + toPageName = "" + fromPageName = "" + pages = list() + for o in sel: + if o.isDerivedFrom("TechDraw::DrawPage"): + pages.append(o) + if pages: + fromPageName = pages[0].Name + if len(pages) > 1: + toPageName = pages[1].Name + + self.ui = TechDrawTools.TaskCopyView() + + self.ui.setValues(vName, fromPageName, toPageName) + Gui.Control.showDialog(self.ui) + + def IsActive(self): + """Return True when the command should be active or False when it should be disabled (greyed).""" + if App.ActiveDocument: + return TechDrawTools.TDToolsUtil.havePage() and TechDrawTools.TDToolsUtil.haveView() + else: + return False + + +# +# The command must be "registered" with a unique name by calling its class. +Gui.addCommand('TechDraw_CopyView', CommandCopyView()) + diff --git a/src/Mod/TechDraw/TechDrawTools/CommandMoveView.py b/src/Mod/TechDraw/TechDrawTools/CommandMoveView.py new file mode 100644 index 0000000000..4b9ce003cc --- /dev/null +++ b/src/Mod/TechDraw/TechDrawTools/CommandMoveView.py @@ -0,0 +1,89 @@ +# *************************************************************************** +# * Copyright (c) 2022 Wanderer Fan * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program 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 program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** +"""Provides the TechDraw MoveView GuiCommand.""" + +__title__ = "TechDrawTools.CommandMoveView" +__author__ = "WandererFan" +__url__ = "http://www.freecadweb.org/index.html" +__version__ = "00.01" +__date__ = "2022/01/11" + +from PySide.QtCore import QT_TRANSLATE_NOOP + +import FreeCAD as App +import FreeCADGui as Gui + +import TechDrawTools + +class CommandMoveView: + """Moves a View from current Page to a different Page.""" + + def __init__(self): + """Initialize variables for the command that must exist at all times.""" + pass + + def GetResources(self): + """Return a dictionary with data that will be used by the button or menu item.""" + return {'Pixmap': 'actions/TechDraw_MoveView.svg', + 'Accel': "", + 'MenuText': QT_TRANSLATE_NOOP("MoveView", "Move View"), + 'ToolTip': QT_TRANSLATE_NOOP("MoveView", "Move a View to a new Page")} + + def Activated(self): + """Run the following code when the command is activated (button press).""" + sel = Gui.Selection.getSelection() + + viewName = "" + views = list() + for o in sel: + if o.isDerivedFrom("TechDraw::DrawView"): + views.append(o) + if views: + viewName = views[0].Name + + toPageName = "" + fromPageName = "" + pages = list() + for o in sel: + if o.isDerivedFrom("TechDraw::DrawPage"): + pages.append(o) + if pages: + fromPageName = pages[0].Name + if len(pages) > 1: + toPageName = pages[1].Name + + self.ui = TechDrawTools.TaskMoveView() + + self.ui.setValues(viewName, fromPageName, toPageName) + Gui.Control.showDialog(self.ui) + + def IsActive(self): + """Return True when the command should be active or False when it should be disabled (greyed).""" + if App.ActiveDocument: + return TechDrawTools.TDToolsUtil.havePage() and TechDrawTools.TDToolsUtil.haveView() + else: + return False + + +# +# The command must be "registered" with a unique name by calling its class. +Gui.addCommand('TechDraw_MoveView', CommandMoveView()) + diff --git a/src/Mod/TechDraw/TechDrawTools/TDToolsMovers.py b/src/Mod/TechDraw/TechDrawTools/TDToolsMovers.py new file mode 100644 index 0000000000..c29df37fa7 --- /dev/null +++ b/src/Mod/TechDraw/TechDrawTools/TDToolsMovers.py @@ -0,0 +1,73 @@ +# *************************************************************************** +# * Copyright (c) 2022 - Wanderer Fan * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program 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 program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** +"""Provides view moving functions for TD Tools.""" + +import FreeCAD as App + +#move a simple view and its dependents (dimensions, balloons, etc) from fromPage to toPage +def simpleViewMove(view, fromPage, toPage, copy): + deps = [x for x in view.InList if x.isDerivedFrom("TechDraw::DrawView")] + if not copy: + for d in deps: + rc = fromPage.removeView(d) + rc = fromPage.removeView(view) + #redraw fromPage without view + fromPage.requestPaint() + + toPage.addView(view) + for d in deps: + toPage.addView(d) + + view.recompute() #update the view feature + App.ActiveDocument.recompute() #update views dependents if necessary + return + +#move a section view, its Base View and all its dependents (items, dimensions, balloons, etc) of both from fromPage to toPage +def sectionViewMove(view, fromPage, toPage, copy): + #move the base + base = view.BaseView + simpleViewMove(base, fromPage, toPage, copy) + +#move a projection group and all its dependents (items, dimensions, balloons, etc) from fromPage to toPage +def projGroupMove(view, fromPage, toPage, copy): + items = [x for x in view.Views if x.isDerivedFrom("TechDraw::DrawProjGroupItem")] + if not copy: + for i in items: + id = [x for x in i.InList if x.isDerivedFrom("TechDraw::DrawView")] + for dep in id: + fromPage.removeView(dep) + fromPage.removeView(view) + + toPage.addView(view) + for i in items: + id = [x for x in i.InList if x.isDerivedFrom("TechDraw::DrawView")] + for dep in id: + if not dep.isDerivedFrom("TechDraw::DrawProjGroup"): #probably superfluous + toPage.addView(dep) + +def moveView(view, fromPage, toPage, copy=False): + if view.isDerivedFrom("TechDraw::DrawProjGroup"): + projGroupMove(view, fromPage, toPage, copy) + elif view.isDerivedFrom("TechDraw::DrawViewSection") or view.isDerivedFrom("TechDraw::DrawViewDetail"): + sectionViewMove(view, fromPage, toPage, copy) + elif view.isDerivedFrom("TechDraw::DrawView"): + simpleViewMove(view, fromPage, toPage, copy) + diff --git a/src/Mod/TechDraw/TechDrawTools/TDToolsUtil.py b/src/Mod/TechDraw/TechDrawTools/TDToolsUtil.py new file mode 100644 index 0000000000..2c2cb44638 --- /dev/null +++ b/src/Mod/TechDraw/TechDrawTools/TDToolsUtil.py @@ -0,0 +1,38 @@ +# *************************************************************************** +# * Copyright (c) 2022 - Wanderer Fan * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program 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 program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** +"""Provides utility funtions for TD Tools.""" + +import FreeCAD as App + +def havePage(): + objs = App.ActiveDocument.Objects + for o in objs: + if o.isDerivedFrom("TechDraw::DrawPage"): + return True + return False + +def haveView(): + objs = App.ActiveDocument.Objects + for o in objs: + if o.isDerivedFrom("TechDraw::DrawView"): + return True + return False + diff --git a/src/Mod/TechDraw/TechDrawTools/TaskCopyView.py b/src/Mod/TechDraw/TechDrawTools/TaskCopyView.py new file mode 100644 index 0000000000..e9fe011f88 --- /dev/null +++ b/src/Mod/TechDraw/TechDrawTools/TaskCopyView.py @@ -0,0 +1,133 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2022 - Wanderer Fan * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program 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 program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** +"""Provides the TechDraw CopyView Task Dialog.""" + +__title__ = "TechDrawTools.TaskCopyView" +__author__ = "WandeererFan" +__url__ = "http://www.freecadweb.org/index.html" +__version__ = "00.01" +__date__ = "2022/01/11" + +from PySide.QtCore import QT_TRANSLATE_NOOP +from PySide import QtCore +import PySide.QtGui as QtGui + +import FreeCAD as App +import FreeCADGui as Gui + +from TechDrawTools import TDToolsMovers + +import os + +class TaskCopyView: + def __init__(self): + self._uiPath = App.getHomePath() + self._uiPath = os.path.join(self._uiPath, "Mod/TechDraw/Gui/TaskMoveView.ui") + self.form = Gui.PySideUic.loadUi(self._uiPath) + + self.form.setWindowTitle(QT_TRANSLATE_NOOP("CopyView", "Copy View to a second Page")) + + self.form.pbView.clicked.connect(self.pickView) + self.form.pbFromPage.clicked.connect(self.pickFromPage) + self.form.pbToPage.clicked.connect(self.pickToPage) + + self.viewName = "" + self.fromPageName = "" + self.toPageName = "" + + def accept(self): +# print ("Accept") + view = App.ActiveDocument.getObject(self.viewName) + fromPage = App.ActiveDocument.getObject(self.fromPageName) + toPage = App.ActiveDocument.getObject(self.toPageName) + TDToolsMovers.moveView(view, fromPage, toPage, True) + return True + + def reject(self): +# print ("Reject") + return True + + def pickView(self): +# print("pickView") + _dlgPath = App.getHomePath() + _dlgPath = os.path.join(_dlgPath, "Mod/TechDraw/Gui/DlgPageChooser.ui") + dlg = Gui.PySideUic.loadUi(_dlgPath) + dlg.lPrompt.setText(QT_TRANSLATE_NOOP("CopyView", "Select View to copy from list.")) + dlg.setWindowTitle(QT_TRANSLATE_NOOP("CopyView", "Select View")) + + views = [x for x in App.ActiveDocument.Objects if x.isDerivedFrom("TechDraw::DrawView")] + for v in views: + s = v.Label + " / " + v.Name + item = QtGui.QListWidgetItem(s, dlg.lwPages) + item.setData(QtCore.Qt.UserRole, v.Name) + if (dlg.exec() == QtGui.QDialog.Accepted) : + if dlg.lwPages.selectedItems(): + selItem = dlg.lwPages.selectedItems()[0] + self.viewName = selItem.data(QtCore.Qt.UserRole) + self.form.leView.setText(self.viewName) + + def pickFromPage(self): +# print("pickFromPage") + _dlgPath = App.getHomePath() + _dlgPath = os.path.join(_dlgPath, "Mod/TechDraw/Gui/DlgPageChooser.ui") + dlg = Gui.PySideUic.loadUi(_dlgPath) + dlg.lPrompt.setText(QT_TRANSLATE_NOOP("CopyView", "Select From Page.")) + dlg.setWindowTitle(QT_TRANSLATE_NOOP("CopyView", "Select Page")) + + pages = [x for x in App.ActiveDocument.Objects if x.isDerivedFrom("TechDraw::DrawPage")] + for p in pages: + s = p.Label + " / " + p.Name + item = QtGui.QListWidgetItem(s, dlg.lwPages) + item.setData(QtCore.Qt.UserRole, p.Name) + if (dlg.exec() == QtGui.QDialog.Accepted) : + if dlg.lwPages.selectedItems(): + selItem = dlg.lwPages.selectedItems()[0] + self.fromPageName = selItem.data(QtCore.Qt.UserRole) + self.form.leFromPage.setText(self.fromPageName) + + def pickToPage(self): +# print("pickToPage") + _dlgPath = App.getHomePath() + _dlgPath = os.path.join(_dlgPath, "Mod/TechDraw/Gui/DlgPageChooser.ui") + dlg = Gui.PySideUic.loadUi(_dlgPath) + dlg.lPrompt.setText(QT_TRANSLATE_NOOP("CopyView", "Select To Page.")) + dlg.setWindowTitle(QT_TRANSLATE_NOOP("CopyView", "Select Page")) + + pages = [x for x in App.ActiveDocument.Objects if x.isDerivedFrom("TechDraw::DrawPage")] + for p in pages: + s = p.Label + " / " + p.Name + item = QtGui.QListWidgetItem(s, dlg.lwPages) + item.setData(QtCore.Qt.UserRole, p.Name) + if (dlg.exec() == QtGui.QDialog.Accepted) : + if dlg.lwPages.selectedItems(): + selItem = dlg.lwPages.selectedItems()[0] + self.toPageName = selItem.data(QtCore.Qt.UserRole) + self.form.leToPage.setText(self.toPageName) + + def setValues(self, viewName, fromPageName, toPageName): + self.viewName = viewName + self.form.leView.setText(viewName) + self.fromPageName = fromPageName + self.form.leFromPage.setText(fromPageName) + self.toPageName = toPageName + self.form.leToPage.setText(toPageName) + diff --git a/src/Mod/TechDraw/TechDrawTools/TaskMoveView.py b/src/Mod/TechDraw/TechDrawTools/TaskMoveView.py new file mode 100644 index 0000000000..925ddd6c5a --- /dev/null +++ b/src/Mod/TechDraw/TechDrawTools/TaskMoveView.py @@ -0,0 +1,134 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2022 - Wanderer Fan * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program 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 program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** +"""Provides the TechDraw MoveView Task Dialog.""" + +__title__ = "TechDrawTools.TaskMoveView" +__author__ = "WandeererFan" +__url__ = "http://www.freecadweb.org/index.html" +__version__ = "00.01" +__date__ = "2022/01/11" + +from PySide.QtCore import QT_TRANSLATE_NOOP +from PySide import QtCore +import PySide.QtGui as QtGui + +import FreeCAD as App +import FreeCADGui as Gui + +from TechDrawTools import TDToolsMovers + +import os + +class TaskMoveView: + def __init__(self): + import os + self._uiPath = App.getHomePath() + self._uiPath = os.path.join(self._uiPath, "Mod/TechDraw/Gui/TaskMoveView.ui") + self.form = Gui.PySideUic.loadUi(self._uiPath) + + self.form.setWindowTitle(QT_TRANSLATE_NOOP("MoveView", "Move View to a different Page")) + + self.form.pbView.clicked.connect(self.pickView) + self.form.pbFromPage.clicked.connect(self.pickFromPage) + self.form.pbToPage.clicked.connect(self.pickToPage) + + self.viewName = "" + self.fromPageName = "" + self.toPageName = "" + + def accept(self): +# print ("Accept") + view = App.ActiveDocument.getObject(self.viewName) + fromPage = App.ActiveDocument.getObject(self.fromPageName) + toPage = App.ActiveDocument.getObject(self.toPageName) + TDToolsMovers.moveView(view, fromPage, toPage) + return True + + def reject(self): +# print ("Reject") + return True + + def pickView(self): +# print("pickView") + _dlgPath = App.getHomePath() + _dlgPath = os.path.join(_dlgPath, "Mod/TechDraw/Gui/DlgPageChooser.ui") + dlg = Gui.PySideUic.loadUi(_dlgPath) + dlg.lPrompt.setText(QT_TRANSLATE_NOOP("MoveView", "Select View to move from list.")) + dlg.setWindowTitle(QT_TRANSLATE_NOOP("MoveView", "Select View")) + + views = [x for x in App.ActiveDocument.Objects if x.isDerivedFrom("TechDraw::DrawView")] + for v in views: + s = v.Label + " / " + v.Name + item = QtGui.QListWidgetItem(s, dlg.lwPages) + item.setData(QtCore.Qt.UserRole, v.Name) + if (dlg.exec() == QtGui.QDialog.Accepted) : + if dlg.lwPages.selectedItems(): + selItem = dlg.lwPages.selectedItems()[0] + self.viewName = selItem.data(QtCore.Qt.UserRole) + self.form.leView.setText(self.viewName) + + def pickFromPage(self): +# print("pickFromPage") + _dlgPath = App.getHomePath() + _dlgPath = os.path.join(_dlgPath, "Mod/TechDraw/Gui/DlgPageChooser.ui") + dlg = Gui.PySideUic.loadUi(_dlgPath) + dlg.lPrompt.setText(QT_TRANSLATE_NOOP("MoveView", "Select From Page.")) + dlg.setWindowTitle(QT_TRANSLATE_NOOP("MoveView", "Select Page")) + + pages = [x for x in App.ActiveDocument.Objects if x.isDerivedFrom("TechDraw::DrawPage")] + for p in pages: + s = p.Label + " / " + p.Label + item = QtGui.QListWidgetItem(s, dlg.lwPages) + item.setData(QtCore.Qt.UserRole, p.Name) + if (dlg.exec() == QtGui.QDialog.Accepted) : + if dlg.lwPages.selectedItems(): + selItem = dlg.lwPages.selectedItems()[0] + self.fromPageName = selItem.data(QtCore.Qt.UserRole) + self.form.leFromPage.setText(self.fromPageName) + + def pickToPage(self): +# print("pickToPage") + _dlgPath = App.getHomePath() + _dlgPath = os.path.join(_dlgPath, "Mod/TechDraw/Gui/DlgPageChooser.ui") + dlg = Gui.PySideUic.loadUi(_dlgPath) + dlg.lPrompt.setText(QT_TRANSLATE_NOOP("MoveView", "Select To Page.")) + dlg.setWindowTitle(QT_TRANSLATE_NOOP("MoveView", "Select Page")) + + pages = [x for x in App.ActiveDocument.Objects if x.isDerivedFrom("TechDraw::DrawPage")] + for p in pages: + s = p.Label + " / " + p.Name + item = QtGui.QListWidgetItem(s, dlg.lwPages) + item.setData(QtCore.Qt.UserRole, p.Name) + if (dlg.exec() == QtGui.QDialog.Accepted) : + if dlg.lwPages.selectedItems(): + selItem = dlg.lwPages.selectedItems()[0] + self.toPageName = selItem.data(QtCore.Qt.UserRole) + self.form.leToPage.setText(self.toPageName) + + def setValues(self, viewName, fromPageName, toPageName): + self.viewName = viewName + self.form.leView.setText(viewName) + self.fromPageName = fromPageName + self.form.leFromPage.setText(fromPageName) + self.toPageName = toPageName + self.form.leToPage.setText(toPageName) + diff --git a/src/Mod/TechDraw/TechDrawTools/__init__.py b/src/Mod/TechDraw/TechDrawTools/__init__.py new file mode 100644 index 0000000000..f193d61484 --- /dev/null +++ b/src/Mod/TechDraw/TechDrawTools/__init__.py @@ -0,0 +1,38 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2022 - Wanderer Fan * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program 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 program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "TechDrawTools package" +__author__ = "WandererFan" +__url__ = "https://www.freecadweb.org" +__version__ = "00.01" +__date__ = "2022-01-11" + +## @package TechDrawTools +# \ingroup TechDraw +# \brief TechDrawTools Package for TechDraw workbench + +from .TDToolsMovers import * +from .TDToolsUtil import * +from .CommandCopyView import CommandCopyView +from .CommandMoveView import CommandMoveView +from .TaskCopyView import TaskCopyView +from .TaskMoveView import TaskMoveView