Merge pull request #192 from DeepSOIC/Sketcher_SmartVisibility
Sketcher visibility automation
This commit is contained in:
commit
4acca01d87
|
@ -198,6 +198,7 @@ OPTION(BUILD_RAYTRACING "Build the FreeCAD ray tracing module" ON)
|
|||
OPTION(BUILD_REVERSEENGINEERING "Build the FreeCAD reverse engineering module" ON)
|
||||
OPTION(BUILD_ROBOT "Build the FreeCAD robot module" ON)
|
||||
OPTION(BUILD_SHIP "Build the FreeCAD ship module" ON)
|
||||
OPTION(BUILD_SHOW "Build the FreeCAD Show module (helper module for visibility automation)" ON)
|
||||
OPTION(BUILD_SKETCHER "Build the FreeCAD sketcher module" ON)
|
||||
OPTION(BUILD_SPREADSHEET "Build the FreeCAD spreadsheet module" ON)
|
||||
OPTION(BUILD_START "Build the FreeCAD start module" ON)
|
||||
|
|
|
@ -125,3 +125,7 @@ endif(BUILD_JTREADER)
|
|||
if(BUILD_PATH)
|
||||
add_subdirectory(Path)
|
||||
endif(BUILD_PATH)
|
||||
|
||||
if(BUILD_SHOW)
|
||||
add_subdirectory(Show)
|
||||
endif(BUILD_SHOW)
|
||||
|
|
|
@ -289,11 +289,9 @@ SET(Part_Scripts
|
|||
JoinFeatures.py
|
||||
AttachmentEditor/__init__.py
|
||||
AttachmentEditor/Commands.py
|
||||
AttachmentEditor/DepGraphTools.py
|
||||
AttachmentEditor/FrozenClass.py
|
||||
AttachmentEditor/TaskAttachmentEditor.py
|
||||
AttachmentEditor/TaskAttachmentEditor.ui
|
||||
AttachmentEditor/TempoVis.py
|
||||
)
|
||||
|
||||
add_library(Part SHARED ${Part_SRCS})
|
||||
|
|
|
@ -31,8 +31,16 @@ from Units import Degree as deg
|
|||
from Units import Quantity as Q
|
||||
|
||||
from AttachmentEditor.FrozenClass import FrozenClass
|
||||
from AttachmentEditor.TempoVis import TempoVis
|
||||
from AttachmentEditor.DepGraphTools import getAllDependent
|
||||
try:
|
||||
from Show.TempoVis import TempoVis
|
||||
from Show.DepGraphTools import getAllDependent
|
||||
except ImportError as err:
|
||||
def TempoVis(doc):
|
||||
return None
|
||||
def getAllDependent(feature):
|
||||
return []
|
||||
App.Console.PrintWarning("AttachmentEditor: Failed to import some code from Show module. Functionality will be limited.\n")
|
||||
App.Console.PrintWarning(err.message)
|
||||
|
||||
if App.GuiUp:
|
||||
import FreeCADGui as Gui
|
||||
|
@ -280,9 +288,10 @@ class AttachmentEditorTaskPanel(FrozenClass):
|
|||
self.updateRefButtons()
|
||||
|
||||
self.tv = TempoVis(self.obj.Document)
|
||||
self.tv.hide_all_dependent(self.obj)
|
||||
self.tv.show(self.obj)
|
||||
self.tv.show([obj for (obj,subname) in self.attacher.References])
|
||||
if self.tv: # tv will still be None if Show module is unavailable
|
||||
self.tv.hide_all_dependent(self.obj)
|
||||
self.tv.show(self.obj)
|
||||
self.tv.show([obj for (obj,subname) in self.attacher.References])
|
||||
|
||||
# task dialog handling
|
||||
def getStandardButtons(self):
|
||||
|
@ -582,4 +591,5 @@ class AttachmentEditorTaskPanel(FrozenClass):
|
|||
def cleanUp(self):
|
||||
'''stuff that needs to be done when dialog is closed.'''
|
||||
Gui.Selection.removeObserver(self)
|
||||
self.tv.restore()
|
||||
if self.tv:
|
||||
self.tv.restore()
|
|
@ -20,11 +20,9 @@ INSTALL(
|
|||
FILES
|
||||
AttachmentEditor/__init__.py
|
||||
AttachmentEditor/Commands.py
|
||||
AttachmentEditor/DepGraphTools.py
|
||||
AttachmentEditor/FrozenClass.py
|
||||
AttachmentEditor/TaskAttachmentEditor.py
|
||||
AttachmentEditor/TaskAttachmentEditor.ui
|
||||
AttachmentEditor/TempoVis.py
|
||||
DESTINATION
|
||||
Mod/Part/AttachmentEditor
|
||||
)
|
||||
|
|
21
src/Mod/Show/CMakeLists.txt
Normal file
21
src/Mod/Show/CMakeLists.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
|
||||
SET(Show_SRCS
|
||||
__init__.py
|
||||
DepGraphTools.py
|
||||
FrozenClass.py
|
||||
TempoVis.py
|
||||
)
|
||||
|
||||
SOURCE_GROUP("" FILES ${Show_SRCS})
|
||||
|
||||
ADD_CUSTOM_TARGET(Show ALL
|
||||
SOURCES ${Show_SRCS}
|
||||
)
|
||||
|
||||
fc_copy_sources(Show "${CMAKE_BINARY_DIR}/Mod/Show" ${Show_SRCS})
|
||||
|
||||
INSTALL(
|
||||
FILES
|
||||
${Show_SRCS}
|
||||
DESTINATION Mod/Show
|
||||
)
|
37
src/Mod/Show/FrozenClass.py
Normal file
37
src/Mod/Show/FrozenClass.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
#/***************************************************************************
|
||||
# * Copyright (c) Victor Titov (DeepSOIC) *
|
||||
# * (vv.titov@gmail.com) 2016 *
|
||||
# * *
|
||||
# * 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 *
|
||||
# * *
|
||||
# ***************************************************************************/
|
||||
|
||||
# adapted from http://stackoverflow.com/a/3603824/6285007
|
||||
class FrozenClass(object):
|
||||
'''FrozenClass: prevents adding new attributes to class outside of __init__'''
|
||||
__isfrozen = False
|
||||
def __setattr__(self, key, value):
|
||||
if self.__isfrozen and not hasattr(self, key):
|
||||
raise TypeError( "{cls} has no attribute {attr}".format(cls= self.__class__.__name__, attr= key) )
|
||||
object.__setattr__(self, key, value)
|
||||
|
||||
def _freeze(self):
|
||||
self.__isfrozen = True
|
||||
|
||||
def _unfreeze(self):
|
||||
self.__isfrozen = False
|
|
@ -25,61 +25,71 @@ import FreeCAD as App
|
|||
if App.GuiUp:
|
||||
import FreeCADGui as Gui
|
||||
|
||||
from FrozenClass import FrozenClass
|
||||
from Show.FrozenClass import FrozenClass
|
||||
|
||||
from DepGraphTools import getAllDependencies, getAllDependent, isContainer
|
||||
from Show.DepGraphTools import getAllDependencies, getAllDependent, isContainer
|
||||
|
||||
class TempoVis(FrozenClass):
|
||||
'''TempoVis - helper object to save visibilities of objects before doing
|
||||
some GUI editing, hiding or showing relevant stuff during edit, and
|
||||
'''TempoVis - helper object to save visibilities of objects before doing
|
||||
some GUI editing, hiding or showing relevant stuff during edit, and
|
||||
then restoring all visibilities after editing.
|
||||
|
||||
|
||||
Constructors:
|
||||
TempoVis(document): creates a new TempoVis. Supplying document is mandatory. Objects not belonging to the document can't be modified via TempoVis.'''
|
||||
|
||||
|
||||
def __define_attributes(self):
|
||||
self.data = {} # dict. key = ("Object","Property"), value = original value of the property
|
||||
|
||||
self.cam_string = "" # inventor ASCII string representing the camera
|
||||
self.viewer = None # viewer the camera is saved from
|
||||
|
||||
self.document = None
|
||||
self.restore_on_delete = False
|
||||
self.restore_on_delete = False # if true, restore() gets called upon object deletion. It becomes False after explicit call to Restore, and set to true by many methods.
|
||||
|
||||
self.links_are_lost = False # set to true after restore from JSON. Indictes to attempt to use ActiveDocument/ActiveViewer instead.
|
||||
|
||||
self._freeze()
|
||||
|
||||
|
||||
def __init__(self, document):
|
||||
self.__define_attributes()
|
||||
|
||||
|
||||
self.document = document
|
||||
|
||||
|
||||
def modifyVPProperty(self, doc_obj_or_list, prop_name, new_value):
|
||||
'''modifyVPProperty(self, doc_obj_or_list, prop_name, new_value): modifies
|
||||
prop_name property of ViewProvider of doc_obj_or_list, and remembers
|
||||
original value of the property. Original values will be restored upon
|
||||
'''modifyVPProperty(self, doc_obj_or_list, prop_name, new_value): modifies
|
||||
prop_name property of ViewProvider of doc_obj_or_list, and remembers
|
||||
original value of the property. Original values will be restored upon
|
||||
TempoVis deletion, or call to restore().'''
|
||||
|
||||
|
||||
if App.GuiUp:
|
||||
if type(doc_obj_or_list) is not list:
|
||||
doc_obj_or_list = [doc_obj_or_list]
|
||||
for doc_obj in doc_obj_or_list:
|
||||
if not hasattr(doc_obj.ViewObject, prop_name):
|
||||
App.Console.PrintWarning("TempoVis: object {obj} has no attribute {attr}. Skipped.\n"
|
||||
.format(obj= doc_obj.Name, attr= prop_name))
|
||||
continue # silently ignore if object doesn't have the property...
|
||||
|
||||
if doc_obj.Document is not self.document: #ignore objects from other documents
|
||||
raise ValueError("Document object to be modified does not belong to document TempoVis was made for.")
|
||||
oldval = getattr(doc_obj.ViewObject, prop_name)
|
||||
setattr(doc_obj.ViewObject, prop_name, new_value)
|
||||
#assert(getattr(doc_obj.ViewObject, prop_name)==new_value)
|
||||
if not self.data.has_key((doc_obj.Name,prop_name)):
|
||||
self.data[(doc_obj.Name,prop_name)] = oldval
|
||||
self.restore_on_delete = True
|
||||
|
||||
|
||||
def show(self, doc_obj_or_list):
|
||||
'''show(doc_obj_or_list): shows objects (sets their Visibility to True). doc_obj_or_list can be a document object, or a list of document objects'''
|
||||
self.modifyVPProperty(doc_obj_or_list, "Visibility", True)
|
||||
|
||||
|
||||
def hide(self, doc_obj_or_list):
|
||||
'''hide(doc_obj_or_list): hides objects (sets their Visibility to False). doc_obj_or_list can be a document object, or a list of document objects'''
|
||||
self.modifyVPProperty(doc_obj_or_list, "Visibility", False)
|
||||
|
||||
|
||||
def hide_all_dependent(self, doc_obj):
|
||||
'''hide_all_dependent(doc_obj): hides all objects that depend on doc_obj. Groups, Parts and Bodies are not hidden by this.'''
|
||||
self.hide( [o for o in getAllDependent(doc_obj) if not isContainer(o)])
|
||||
|
||||
|
||||
def show_all_dependent(self, doc_obj):
|
||||
'''show_all_dependent(doc_obj): shows all objects that depend on doc_obj. This method is probably useless.'''
|
||||
self.show( getAllDependent(doc_obj) )
|
||||
|
@ -87,24 +97,78 @@ class TempoVis(FrozenClass):
|
|||
def hide_all_dependencies(self, doc_obj):
|
||||
'''hide_all_dependencies(doc_obj): hides all objects that doc_obj depends on (directly and indirectly).'''
|
||||
self.hide( getAllDependencies(doc_obj) )
|
||||
|
||||
|
||||
def show_all_dependencies(self, doc_obj):
|
||||
'''show_all_dependencies(doc_obj): shows all objects that doc_obj depends on (directly and indirectly). This method is probably useless.'''
|
||||
self.show( getAllDependencies(doc_obj) )
|
||||
|
||||
|
||||
def saveCamera(self):
|
||||
vw = Gui.ActiveDocument.ActiveView
|
||||
self.cam_string = vw.getCamera()
|
||||
self.viewer = vw
|
||||
|
||||
self.restore_on_delete = True
|
||||
|
||||
def restoreCamera(self):
|
||||
if not self.cam_string:
|
||||
return
|
||||
vw = self.viewer
|
||||
if self.links_are_lost: # can happen after save-restore
|
||||
import FreeCADGui as Gui
|
||||
vw = Gui.ActiveDocument.ActiveView
|
||||
|
||||
vw.setCamera(self.cam_string)
|
||||
|
||||
def restore(self):
|
||||
'''restore(): restore all ViewProvider properties modified via TempoVis to their original values. Called automatically when instance is destroyed, unless it was called explicitly.'''
|
||||
'''restore(): restore all ViewProvider properties modified via TempoVis to their
|
||||
original values, and saved camera, if any. Called automatically when instance is
|
||||
destroyed, unless it was called explicitly. Should not raise exceptions.'''
|
||||
|
||||
if self.links_are_lost:
|
||||
self.document = App.ActiveDocument
|
||||
self.viewer = Gui.ActiveDocument.ActiveView
|
||||
self.links_are_lost = False
|
||||
|
||||
for obj_name, prop_name in self.data:
|
||||
setattr(self.document.getObject(obj_name).ViewObject, prop_name, self.data[(obj_name, prop_name)])
|
||||
try:
|
||||
setattr(self.document.getObject(obj_name).ViewObject, prop_name, self.data[(obj_name, prop_name)])
|
||||
except Exception as err:
|
||||
App.Console.PrintWarning("TempoVis: failed to restore {obj}.{prop}. {err}\n"
|
||||
.format(err= err.message,
|
||||
obj= obj_name,
|
||||
prop= prop_name))
|
||||
try:
|
||||
self.restoreCamera()
|
||||
except Exception as err:
|
||||
App.Console.PrintWarning("TempoVis: failed to restore camera. {err}\n"
|
||||
.format(err= err.message))
|
||||
self.restore_on_delete = False
|
||||
|
||||
|
||||
def forget(self):
|
||||
'''forget(): resets TempoVis'''
|
||||
self.data = {}
|
||||
self.restore_on_delete = False
|
||||
|
||||
|
||||
self.cam_string = ""
|
||||
self.viewer = None
|
||||
|
||||
self.restore_on_delete = False
|
||||
|
||||
def __del__(self):
|
||||
if self.restore_on_delete:
|
||||
self.restore()
|
||||
|
||||
|
||||
|
||||
def __getstate__(self):
|
||||
return (self.data.items(),
|
||||
self.cam_string,
|
||||
self.restore_on_delete)
|
||||
|
||||
def __setstate__(self, state):
|
||||
self.__define_attributes()
|
||||
|
||||
items, self.cam_string, self.restore_on_delete = state
|
||||
|
||||
# need to convert keys to tuples (dict doesn't accept list as key; tuples are converted to lists by json)
|
||||
items = [(tuple(item[0]), item[1]) for item in items]
|
||||
self.data = dict(items)
|
||||
self.links_are_lost = True
|
||||
|
4
src/Mod/Show/__init__.py
Normal file
4
src/Mod/Show/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
__doc__ = "Show module: helper code for visibility automation."
|
||||
|
||||
from Show.TempoVis import TempoVis
|
||||
import Show.DepGraphTools as DepGraphTools
|
|
@ -26,14 +26,18 @@
|
|||
#ifndef _PreComp_
|
||||
# include <QPainter>
|
||||
# include <QPixmap>
|
||||
# include <QMessageBox>
|
||||
#endif
|
||||
|
||||
#include "SketcherSettings.h"
|
||||
#include "ui_SketcherSettings.h"
|
||||
#include "TaskSketcherGeneral.h"
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <App/Application.h>
|
||||
#include <Gui/PrefWidgets.h>
|
||||
#include <Gui/Inventor/MarkerBitmaps.h>
|
||||
#include <Gui/Command.h>
|
||||
|
||||
using namespace SketcherGui;
|
||||
|
||||
|
@ -82,6 +86,8 @@ SketcherSettings::SketcherSettings(QWidget* parent)
|
|||
|
||||
ui->comboBox->addItem(QIcon(px), QString(), QVariant(it->second));
|
||||
}
|
||||
|
||||
connect(ui->btnTVApply, SIGNAL(clicked(bool)), this, SLOT(onBtnTVApplyClicked(bool)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,6 +125,10 @@ void SketcherSettings::saveSettings()
|
|||
ui->dialogOnDistanceConstraint->onSave();
|
||||
ui->continueMode->onSave();
|
||||
ui->checkBoxAdvancedSolverTaskBox->onSave();
|
||||
ui->checkBoxTVHideDependent->onSave();
|
||||
ui->checkBoxTVShowLinks->onSave();
|
||||
ui->checkBoxTVShowSupport->onSave();
|
||||
ui->checkBoxTVRestoreCamera->onSave();
|
||||
form->saveSettings();
|
||||
|
||||
ParameterGrp::handle hViewGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
|
||||
|
@ -157,6 +167,10 @@ void SketcherSettings::loadSettings()
|
|||
ui->dialogOnDistanceConstraint->onRestore();
|
||||
ui->continueMode->onRestore();
|
||||
ui->checkBoxAdvancedSolverTaskBox->onRestore();
|
||||
ui->checkBoxTVHideDependent->onRestore();
|
||||
ui->checkBoxTVShowLinks->onRestore();
|
||||
ui->checkBoxTVShowSupport->onRestore();
|
||||
ui->checkBoxTVRestoreCamera->onRestore();
|
||||
form->loadSettings();
|
||||
|
||||
std::list<int> sizes = Gui::Inventor::MarkerBitmaps::getSupportedSizes("CIRCLE_FILLED");
|
||||
|
@ -189,5 +203,32 @@ void SketcherSettings::changeEvent(QEvent *e)
|
|||
}
|
||||
}
|
||||
|
||||
void SketcherSettings::onBtnTVApplyClicked(bool)
|
||||
{
|
||||
QString errMsg;
|
||||
try{
|
||||
Gui::Command::doCommand(Gui::Command::Gui,
|
||||
"for name,doc in App.listDocuments().items():\n"
|
||||
" for sketch in doc.findObjects('Sketcher::SketchObject'):\n"
|
||||
" sketch.ViewObject.HideDependent = %s\n"
|
||||
" sketch.ViewObject.ShowLinks = %s\n"
|
||||
" sketch.ViewObject.ShowSupport = %s\n"
|
||||
" sketch.ViewObject.RestoreCamera = %s\n",
|
||||
this->ui->checkBoxTVHideDependent->isChecked() ? "True": "False",
|
||||
this->ui->checkBoxTVShowLinks->isChecked() ? "True": "False",
|
||||
this->ui->checkBoxTVShowSupport->isChecked() ? "True": "False",
|
||||
this->ui->checkBoxTVRestoreCamera->isChecked() ? "True": "False");
|
||||
} catch (Base::PyException &e){
|
||||
Base::Console().Error("SketcherSettings::onBtnTVApplyClicked:\n");
|
||||
e.ReportException();
|
||||
errMsg = QString::fromLatin1(e.what());
|
||||
} catch (...) {
|
||||
errMsg = tr("Unexpected C++ exception");
|
||||
}
|
||||
if(errMsg.length()>0){
|
||||
QMessageBox::warning(this, tr("Sketcher"),errMsg);
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_SketcherSettings.cpp"
|
||||
|
||||
|
|
|
@ -47,6 +47,9 @@ public:
|
|||
protected:
|
||||
void changeEvent(QEvent *e);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onBtnTVApplyClicked(bool);
|
||||
|
||||
private:
|
||||
Ui_SketcherSettings* ui;
|
||||
SketcherGeneralWidget* form;
|
||||
|
|
|
@ -6,14 +6,49 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>404</width>
|
||||
<height>744</height>
|
||||
<width>427</width>
|
||||
<height>1253</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Sketcher</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="7" 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>
|
||||
<item row="3" column="0">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Sketch Solver</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
<widget class="Gui::PrefCheckBox" name="checkBoxAdvancedSolverTaskBox">
|
||||
<property name="text">
|
||||
<string>Show Advanced Solver Control in the Task bar</string>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>ShowSolverAdvancedWidget</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Sketcher</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="groupBoxSketcherColor">
|
||||
<property name="title">
|
||||
|
@ -40,7 +75,7 @@
|
|||
<property name="toolTip">
|
||||
<string>The color of edges being edited</string>
|
||||
</property>
|
||||
<property name="color">
|
||||
<property name="color" stdset="0">
|
||||
<color>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
|
@ -73,7 +108,7 @@
|
|||
<property name="toolTip">
|
||||
<string>The color of vertices being edited</string>
|
||||
</property>
|
||||
<property name="color">
|
||||
<property name="color" stdset="0">
|
||||
<color>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
|
@ -106,7 +141,7 @@
|
|||
<property name="toolTip">
|
||||
<string>The color of edges being edited</string>
|
||||
</property>
|
||||
<property name="color">
|
||||
<property name="color" stdset="0">
|
||||
<color>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
|
@ -139,7 +174,7 @@
|
|||
<property name="toolTip">
|
||||
<string>The color of vertices being edited</string>
|
||||
</property>
|
||||
<property name="color">
|
||||
<property name="color" stdset="0">
|
||||
<color>
|
||||
<red>255</red>
|
||||
<green>38</green>
|
||||
|
@ -172,7 +207,7 @@
|
|||
<property name="toolTip">
|
||||
<string>The color of fully constrained geometry in edit mode</string>
|
||||
</property>
|
||||
<property name="color">
|
||||
<property name="color" stdset="0">
|
||||
<color>
|
||||
<red>255</red>
|
||||
<green>38</green>
|
||||
|
@ -192,7 +227,7 @@
|
|||
<property name="toolTip">
|
||||
<string>The color of construction geometry in edit mode</string>
|
||||
</property>
|
||||
<property name="color">
|
||||
<property name="color" stdset="0">
|
||||
<color>
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
|
@ -225,7 +260,7 @@
|
|||
<property name="toolTip">
|
||||
<string>The color of external geometry in edit mode</string>
|
||||
</property>
|
||||
<property name="color">
|
||||
<property name="color" stdset="0">
|
||||
<color>
|
||||
<red>204</red>
|
||||
<green>51</green>
|
||||
|
@ -271,7 +306,7 @@
|
|||
<property name="toolTip">
|
||||
<string>The color of fully constrained geometry in edit mode</string>
|
||||
</property>
|
||||
<property name="color">
|
||||
<property name="color" stdset="0">
|
||||
<color>
|
||||
<red>0</red>
|
||||
<green>255</green>
|
||||
|
@ -397,7 +432,7 @@
|
|||
</item>
|
||||
<item row="13" column="1">
|
||||
<widget class="Gui::PrefColorButton" name="CursorTextColor">
|
||||
<property name="color">
|
||||
<property name="color" stdset="0">
|
||||
<color>
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
|
@ -446,7 +481,7 @@
|
|||
<property name="toolTip">
|
||||
<string>The color of driving constraints in edit mode</string>
|
||||
</property>
|
||||
<property name="color">
|
||||
<property name="color" stdset="0">
|
||||
<color>
|
||||
<red>255</red>
|
||||
<green>38</green>
|
||||
|
@ -466,7 +501,7 @@
|
|||
<property name="toolTip">
|
||||
<string>The color of non-driving constrains or dimensions in edit mode</string>
|
||||
</property>
|
||||
<property name="color">
|
||||
<property name="color" stdset="0">
|
||||
<color>
|
||||
<red>0</red>
|
||||
<green>38</green>
|
||||
|
@ -492,19 +527,6 @@
|
|||
<string>Sketch editing</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>182</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Font size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="Gui::PrefSpinBox" name="EditSketcherFontSize">
|
||||
<property name="suffix">
|
||||
|
@ -540,13 +562,16 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="EditSketcherMarkerSize"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>182</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Grid line pattern</string>
|
||||
<string>Font size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -573,6 +598,16 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="EditSketcherMarkerSize"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Grid line pattern</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="Gui::PrefCheckBox" name="continueMode">
|
||||
<property name="text">
|
||||
|
@ -589,44 +624,156 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Sketch Solver</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
<widget class="Gui::PrefCheckBox" name="checkBoxAdvancedSolverTaskBox">
|
||||
<property name="text">
|
||||
<string>Show Advanced Solver Control in the Task bar</string>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>ShowSolverAdvancedWidget</cstring>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Sketcher</cstring>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Visibility automation</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="Gui::PrefCheckBox" name="checkBoxTVHideDependent">
|
||||
<property name="toolTip">
|
||||
<string>When opening sketch, hide all features that depend on it.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Hide all objects that depend on the sketch</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>HideDependent</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Sketcher/General</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::PrefCheckBox" name="checkBoxTVShowLinks">
|
||||
<property name="toolTip">
|
||||
<string>When opening sketch, show sources for external geometry links.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Show objects used for external geometry</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>ShowLinks</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Sketcher/General</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::PrefCheckBox" name="checkBoxTVShowSupport">
|
||||
<property name="toolTip">
|
||||
<string>When opening sketch, show objects the sketch is attached to.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Show object(s) sketch is attached to</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>ShowSupport</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Sketcher/General</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::PrefCheckBox" name="checkBoxTVRestoreCamera">
|
||||
<property name="toolTip">
|
||||
<string>When closing sketch, move camera back to where it was before sketch was opened.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Restore camera position after editing</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="prefEntry" stdset="0">
|
||||
<cstring>RestoreCamera</cstring>
|
||||
</property>
|
||||
<property name="prefPath" stdset="0">
|
||||
<cstring>Mod/Sketcher/General</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Note: these settings are defaults applied to new sketches. The behavior is remembered for each sketch individually as properties on View tab.</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnTVApply">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Apply current smart visibility to all sketches in open documents (update properties to match).</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Apply to existing sketches</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>217</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
@ -652,11 +799,31 @@
|
|||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>CursorTextColor</tabstop>
|
||||
<tabstop>SketchEdgeColor</tabstop>
|
||||
<tabstop>SketchVertexColor</tabstop>
|
||||
<tabstop>EditedEdgeColor</tabstop>
|
||||
<tabstop>EditedVertexColor</tabstop>
|
||||
<tabstop>ConstructionColor</tabstop>
|
||||
<tabstop>ExternalColor</tabstop>
|
||||
<tabstop>FullyConstrainedColor</tabstop>
|
||||
<tabstop>ConstrainedColor</tabstop>
|
||||
<tabstop>NonDrivingConstraintColor</tabstop>
|
||||
<tabstop>DatumColor</tabstop>
|
||||
<tabstop>SketcherDatumWidth</tabstop>
|
||||
<tabstop>DefaultSketcherVertexWidth</tabstop>
|
||||
<tabstop>DefaultSketcherLineWidth</tabstop>
|
||||
<tabstop>CursorTextColor</tabstop>
|
||||
<tabstop>EditSketcherFontSize</tabstop>
|
||||
<tabstop>EditSketcherMarkerSize</tabstop>
|
||||
<tabstop>comboBox</tabstop>
|
||||
<tabstop>dialogOnDistanceConstraint</tabstop>
|
||||
<tabstop>continueMode</tabstop>
|
||||
<tabstop>checkBoxTVHideDependent</tabstop>
|
||||
<tabstop>checkBoxTVShowLinks</tabstop>
|
||||
<tabstop>checkBoxTVShowSupport</tabstop>
|
||||
<tabstop>checkBoxTVRestoreCamera</tabstop>
|
||||
<tabstop>btnTVApply</tabstop>
|
||||
<tabstop>checkBoxAdvancedSolverTaskBox</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
#include <Base/Parameter.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Vector3D.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Document.h>
|
||||
|
@ -190,7 +191,6 @@ struct EditData {
|
|||
std::set<int> PreselectConstraintSet;
|
||||
bool blockedPreselection;
|
||||
bool FullyConstrained;
|
||||
bool visibleBeforeEdit;
|
||||
|
||||
// container to track our own selected parts
|
||||
std::set<int> SelPointSet;
|
||||
|
@ -255,8 +255,20 @@ ViewProviderSketch::ViewProviderSketch()
|
|||
: edit(0),
|
||||
Mode(STATUS_NONE)
|
||||
{
|
||||
// FIXME Should this be placed in here?
|
||||
ADD_PROPERTY_TYPE(Autoconstraints,(true),"Auto Constraints",(App::PropertyType)(App::Prop_None),"Create auto constraints");
|
||||
ADD_PROPERTY_TYPE(TempoVis,(Py::None()),"Visibility automation",(App::PropertyType)(App::Prop_None),"Object that handles hiding and showing other objects when entering/leaving sketch.");
|
||||
ADD_PROPERTY_TYPE(HideDependent,(true),"Visibility automation",(App::PropertyType)(App::Prop_None),"If true, all objects that depend on the sketch are hidden when opening editing.");
|
||||
ADD_PROPERTY_TYPE(ShowLinks,(true),"Visibility automation",(App::PropertyType)(App::Prop_None),"If true, all objects used in links to external geometry are shown when opening sketch.");
|
||||
ADD_PROPERTY_TYPE(ShowSupport,(true),"Visibility automation",(App::PropertyType)(App::Prop_None),"If true, all objects this sketch is attached to are shown when opening sketch.");
|
||||
ADD_PROPERTY_TYPE(RestoreCamera,(true),"Visibility automation",(App::PropertyType)(App::Prop_None),"If true, camera position before entering sketch is remembered, and restored after closing it.");
|
||||
|
||||
{//visibility automation: update defaults to follow preferences
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher/General");
|
||||
this->HideDependent.setValue(hGrp->GetBool("HideDependent", true));
|
||||
this->ShowLinks.setValue(hGrp->GetBool("ShowLinks", true));
|
||||
this->ShowSupport.setValue(hGrp->GetBool("ShowSupport", true));
|
||||
this->RestoreCamera.setValue(hGrp->GetBool("RestoreCamera", true));
|
||||
}
|
||||
|
||||
sPixmap = "Sketcher_Sketch";
|
||||
LineColor.setValue(1,1,1);
|
||||
|
@ -4219,8 +4231,35 @@ bool ViewProviderSketch::setEdit(int ModNum)
|
|||
edit->MarkerSize = hGrp->GetInt("EditSketcherMarkerSize", 7);
|
||||
|
||||
createEditInventorNodes();
|
||||
edit->visibleBeforeEdit = this->isVisible();
|
||||
this->hide(); // avoid that the wires interfere with the edit lines
|
||||
|
||||
//visibility automation
|
||||
try{
|
||||
Gui::Command::addModule(Gui::Command::Gui,"Show.TempoVis");
|
||||
try{
|
||||
QString cmdstr = QString::fromLatin1(
|
||||
"ActiveSketch = App.ActiveDocument.getObject('{sketch_name}')\n"
|
||||
"tv = Show.TempoVis(App.ActiveDocument)\n"
|
||||
"if ActiveSketch.ViewObject.HideDependent:\n"
|
||||
" tv.hide_all_dependent(ActiveSketch)\n"
|
||||
"if ActiveSketch.ViewObject.ShowSupport:\n"
|
||||
" tv.show([ref[0] for ref in ActiveSketch.Support])\n"
|
||||
"if ActiveSketch.ViewObject.ShowLinks:\n"
|
||||
" tv.show([ref[0] for ref in ActiveSketch.ExternalGeometry])\n"
|
||||
"tv.hide(ActiveSketch)\n"
|
||||
"ActiveSketch.ViewObject.TempoVis = tv\n"
|
||||
"del(tv)\n"
|
||||
);
|
||||
cmdstr.replace(QString::fromLatin1("{sketch_name}"),QString::fromLatin1(this->getSketchObject()->getNameInDocument()));
|
||||
QByteArray cmdstr_bytearray = cmdstr.toLatin1();
|
||||
Gui::Command::doCommand(Gui::Command::Gui, cmdstr_bytearray.data());
|
||||
} catch (Base::PyException &e){
|
||||
Base::Console().Error("ViewProviderSketch::setEdit: visibility automation failed with an error: \n");
|
||||
e.ReportException();
|
||||
}
|
||||
} catch (Base::PyException &){
|
||||
Base::Console().Warning("ViewProviderSketch::setEdit: could not import Show module. Visibility automation will not work.\n");
|
||||
}
|
||||
|
||||
|
||||
ShowGrid.setValue(true);
|
||||
TightGrid.setValue(false);
|
||||
|
@ -4565,10 +4604,23 @@ void ViewProviderSketch::unsetEdit(int ModNum)
|
|||
edit->EditRoot->removeAllChildren();
|
||||
pcRoot->removeChild(edit->EditRoot);
|
||||
|
||||
if (edit->visibleBeforeEdit)
|
||||
this->show();
|
||||
else
|
||||
this->hide();
|
||||
//visibility autoation
|
||||
try{
|
||||
QString cmdstr = QString::fromLatin1(
|
||||
"ActiveSketch = App.ActiveDocument.getObject('{sketch_name}')\n"
|
||||
"tv = ActiveSketch.ViewObject.TempoVis\n"
|
||||
"if tv:\n"
|
||||
" tv.restore()\n"
|
||||
"ActiveSketch.ViewObject.TempoVis = None\n"
|
||||
"del(tv)\n"
|
||||
);
|
||||
cmdstr.replace(QString::fromLatin1("{sketch_name}"),QString::fromLatin1(this->getSketchObject()->getNameInDocument()));
|
||||
QByteArray cmdstr_bytearray = cmdstr.toLatin1();
|
||||
Gui::Command::doCommand(Gui::Command::Gui, cmdstr_bytearray.data());
|
||||
} catch (Base::PyException &e){
|
||||
Base::Console().Error("ViewProviderSketch::unsetEdit: visibility automation failed with an error: \n");
|
||||
e.ReportException();
|
||||
}
|
||||
|
||||
delete edit;
|
||||
edit = 0;
|
||||
|
@ -4601,6 +4653,23 @@ void ViewProviderSketch::unsetEdit(int ModNum)
|
|||
|
||||
void ViewProviderSketch::setEditViewer(Gui::View3DInventorViewer* viewer, int ModNum)
|
||||
{
|
||||
//visibility automation: save camera
|
||||
if (! this->TempoVis.getValue().isNone()){
|
||||
try{
|
||||
QString cmdstr = QString::fromLatin1(
|
||||
"ActiveSketch = App.ActiveDocument.getObject('{sketch_name}')\n"
|
||||
"if ActiveSketch.ViewObject.RestoreCamera:\n"
|
||||
" ActiveSketch.ViewObject.TempoVis.saveCamera()\n"
|
||||
);
|
||||
cmdstr.replace(QString::fromLatin1("{sketch_name}"),QString::fromLatin1(this->getSketchObject()->getNameInDocument()));
|
||||
QByteArray cmdstr_bytearray = cmdstr.toLatin1();
|
||||
Gui::Command::doCommand(Gui::Command::Gui, cmdstr_bytearray.data());
|
||||
} catch (Base::PyException &e){
|
||||
Base::Console().Error("ViewProviderSketch::setEdit: visibility automation failed with an error: \n");
|
||||
e.ReportException();
|
||||
}
|
||||
}
|
||||
|
||||
Base::Placement plm = getPlacement();
|
||||
Base::Rotation tmp(plm.getRotation());
|
||||
|
||||
|
|
|
@ -99,6 +99,11 @@ public:
|
|||
virtual ~ViewProviderSketch();
|
||||
|
||||
App::PropertyBool Autoconstraints;
|
||||
App::PropertyPythonObject TempoVis;
|
||||
App::PropertyBool HideDependent;
|
||||
App::PropertyBool ShowLinks;
|
||||
App::PropertyBool ShowSupport;
|
||||
App::PropertyBool RestoreCamera;
|
||||
|
||||
/// Draw all constraint icons
|
||||
/*! Except maybe the radius and lock ones? */
|
||||
|
|
Loading…
Reference in New Issue
Block a user