[TD]Add MoveView and CopyView commands

This commit is contained in:
Wanderer Fan
2022-01-18 10:21:19 -05:00
committed by WandererFan
parent d1a94de371
commit 5a40cd0ae5
16 changed files with 2018 additions and 2 deletions

View File

@@ -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

View File

@@ -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})

View File

@@ -24,7 +24,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<widget class="QLabel" name="lPrompt">
<property name="text">
<string>FreeCAD could not determine which Page to use. Please select a Page.</string>
</property>

View File

@@ -109,6 +109,8 @@
<file>icons/actions/TechDraw_Symbol.svg</file>
<file>icons/actions/TechDraw_Tile.svg</file>
<file>icons/actions/TechDraw_WeldSymbol.svg</file>
<file>icons/actions/TechDraw_MoveView.svg</file>
<file>icons/actions/TechDraw_CopyView.svg</file>
<file>icons/actions/section-up.svg</file>
<file>icons/actions/section-down.svg</file>
<file>icons/actions/section-left.svg</file>

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 22 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TaskMoveView</class>
<widget class="QWidget" name="TaskMoveView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>159</height>
</rect>
</property>
<property name="windowTitle">
<string>Move View</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout" columnstretch="2,3,0">
<item row="0" column="2">
<widget class="QPushButton" name="pbView">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="pbFromPage">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leView">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="pbToPage">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="leToPage">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="leFromPage">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lFromPage">
<property name="text">
<string>From Page</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lToPage">
<property name="text">
<string>To Page</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lViewName">
<property name="text">
<string>View to move</string>
</property>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -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");

View File

@@ -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"

View File

@@ -0,0 +1,90 @@
# ***************************************************************************
# * Copyright (c) 2022 Wanderer Fan <wandererfan@gmail.com> *
# * *
# * 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())

View File

@@ -0,0 +1,89 @@
# ***************************************************************************
# * Copyright (c) 2022 Wanderer Fan <wandererfan@gmail.com> *
# * *
# * 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())

View File

@@ -0,0 +1,73 @@
# ***************************************************************************
# * Copyright (c) 2022 - Wanderer Fan <wandererfan@gmail.com> *
# * *
# * 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)

View File

@@ -0,0 +1,38 @@
# ***************************************************************************
# * Copyright (c) 2022 - Wanderer Fan <wandererfan@gmail.com> *
# * *
# * 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

View File

@@ -0,0 +1,133 @@
# ***************************************************************************
# * *
# * Copyright (c) 2022 - Wanderer Fan <wandererfan@gmail.com> *
# * *
# * 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)

View File

@@ -0,0 +1,134 @@
# ***************************************************************************
# * *
# * Copyright (c) 2022 - Wanderer Fan <wandererfan@gmail.com> *
# * *
# * 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)

View File

@@ -0,0 +1,38 @@
# ***************************************************************************
# * *
# * Copyright (c) 2022 - Wanderer Fan <wandererfan@gmail.com> *
# * *
# * 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