From 2d3abc9c3435c99df44330cd362f0e4fecb999b9 Mon Sep 17 00:00:00 2001 From: kbwbe Date: Tue, 1 Jan 2019 21:12:30 +0100 Subject: [PATCH 1/5] toolbar with constraints restored --- InitGui.py | 15 +- a2p_constraintDialog.py | 9 +- a2p_constraintcommands.py | 292 ++++++++++++++++++++++++++++++++++++++ a2p_constraints.py | 5 + 4 files changed, 318 insertions(+), 3 deletions(-) create mode 100644 a2p_constraintcommands.py diff --git a/InitGui.py b/InitGui.py index 0e073af6..ac207d4e 100644 --- a/InitGui.py +++ b/InitGui.py @@ -55,7 +55,8 @@ def Initialize(self): import a2p_MuxAssembly import a2p_partinformation import a2p_constraintDialog - import a2p_bom #bill of materials == partslist + import a2p_constraintcommands + import a2p_bom # bom == bill of materials == partslist partCommands = [ 'a2p_ImportPart', @@ -68,6 +69,18 @@ def Initialize(self): constraintCommands = [ 'a2p_ConstraintDialogCommand', 'a2p_EditConstraintCommand', + 'a2p_PointIdentityConstraintCommand', + 'a2p_PointOnLineConstraintCommand', + 'a2p_PointOnPlaneConstraintCommand', + 'a2p_SphericalSurfaceConstraintCommand', + 'a2p_CircularEdgeConnection', + 'a2p_AxialConstraintCommand', + 'a2p_AxisParallelConstraintCommand', + 'a2p_AxisPlaneParallelCommand', + 'a2p_PlanesParallelConstraintCommand', + 'a2p_PlaneCoincidentConstraintCommand', + 'a2p_AngledPlanesConstraintCommand', + 'a2p_DeleteConnectionsCommand', ] solverCommands = [ diff --git a/a2p_constraintDialog.py b/a2p_constraintDialog.py index c1baa14e..411117f2 100644 --- a/a2p_constraintDialog.py +++ b/a2p_constraintDialog.py @@ -654,14 +654,14 @@ def manageConstraint(self): @QtCore.Slot() def onAcceptConstraint(self): - self.constraintValueBox.deleteLater() + #self.constraintValueBox.deleteLater() a2plib.setConstraintEditorRef(None) self.activeConstraint = None FreeCADGui.Selection.clearSelection() @QtCore.Slot() def onDeleteConstraint(self): - self.constraintValueBox.deleteLater() + #self.constraintValueBox.deleteLater() a2plib.setConstraintEditorRef(None) self.activeConstraint = None FreeCADGui.Selection.clearSelection() @@ -738,6 +738,7 @@ def __init__(self,constraintObject, mode): self.constraintObject = constraintObject self.resize(300,300) # + print (constraintObject) cvw = a2p_ConstraintValueWidget( None, constraintObject, @@ -760,9 +761,13 @@ def __init__(self,constraintObject, mode): def onAcceptConstraint(self): self.Accepted.emit() + a2plib.setConstraintEditorRef(None) + self.deleteLater() def onDeleteConstraint(self): self.Deleted.emit() + a2plib.setConstraintEditorRef(None) + self.deleteLater() def closeEvent(self,event): self.widget().cancelOperation() diff --git a/a2p_constraintcommands.py b/a2p_constraintcommands.py new file mode 100644 index 00000000..9fc7758c --- /dev/null +++ b/a2p_constraintcommands.py @@ -0,0 +1,292 @@ +#*************************************************************************** +#* * +#* Copyright (c) 2019 kbwbe * +#* * +#* Portions of code based on hamish's assembly 2 * +#* * +#* 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 * +#* * +#*************************************************************************** + +import FreeCAD, FreeCADGui, Part +from PySide import QtGui, QtCore +import os, sys, math, copy +from a2p_viewProviderProxies import * +from FreeCAD import Base + +from a2plib import * +from a2p_solversystem import solveConstraints +import a2p_constraints, a2p_constraintDialog + +#============================================================================== +class a2p_PointIdentityConstraintCommand: + def Activated(self): + selection = FreeCADGui.Selection.getSelectionEx() + + if not a2p_constraints.PointIdentityConstraint.isValidSelection(): + return + + c = a2p_constraints.PointIdentityConstraint(selection) + cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( + c.constraintObject, + 'createConstraint' + ) + FreeCADGui.Selection.clearSelection() + + def GetResources(self): + return { + 'Pixmap' : path_a2p + '/icons/a2p_PointIdentity.svg', + 'MenuText': 'Add PointIdentity Constraint', + 'ToolTip': a2p_constraints.PointIdentityConstraint.getToolTip() + } + +FreeCADGui.addCommand('a2p_PointIdentityConstraintCommand', a2p_PointIdentityConstraintCommand()) + +#============================================================================== +class a2p_PointOnLineConstraintCommand: + def Activated(self): + selection = FreeCADGui.Selection.getSelectionEx() + + if not a2p_constraints.PointOnLineConstraint.isValidSelection(): + return + + c = a2p_constraints.PointOnLineConstraint(selection) + cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( + c.constraintObject, + 'createConstraint' + ) + FreeCADGui.Selection.clearSelection() + + def GetResources(self): + return { + 'Pixmap' : path_a2p + '/icons/a2p_PointOnLineConstraint.svg', + 'MenuText': 'Add PointOnLine constraint', + 'ToolTip': a2p_constraints.PointOnLineConstraint.getToolTip() + } + +FreeCADGui.addCommand('a2p_PointOnLineConstraintCommand', a2p_PointOnLineConstraintCommand()) + +#============================================================================== +class a2p_PointOnPlaneConstraintCommand: + def Activated(self): + selection = FreeCADGui.Selection.getSelectionEx() + + if not a2p_constraints.PointOnPlaneConstraint.isValidSelection(): + return + + c = a2p_constraints.PointOnPlaneConstraint(selection) + cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( + c.constraintObject, + 'createConstraint' + ) + FreeCADGui.Selection.clearSelection() + + def GetResources(self): + return { + 'Pixmap' : path_a2p + '/icons/a2p_PointOnPlaneConstraint.svg', + 'MenuText': 'Add PointOnPlane constraint', + 'ToolTip': a2p_constraints.PointOnPlaneConstraint.getToolTip() + } + +FreeCADGui.addCommand('a2p_PointOnPlaneConstraintCommand', a2p_PointOnPlaneConstraintCommand()) +#============================================================================== +class a2p_SphericalSurfaceConstraintCommand: + def Activated(self): + selection = FreeCADGui.Selection.getSelectionEx() + + if not a2p_constraints.SphericalConstraint.isValidSelection(): + return + + c = a2p_constraints.SphericalConstraint(selection) + cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( + c.constraintObject, + 'createConstraint' + ) + FreeCADGui.Selection.clearSelection() + + def GetResources(self): + return { + 'Pixmap' : path_a2p + '/icons/a2p_SphericalSurfaceConstraint.svg', + 'MenuText': 'Add a spherical constraint', + 'ToolTip': a2p_constraints.SphericalConstraint.getToolTip() + } + +FreeCADGui.addCommand('a2p_SphericalSurfaceConstraintCommand', a2p_SphericalSurfaceConstraintCommand()) +#============================================================================== +class a2p_CircularEdgeConnectionCommand: + def Activated(self): + selection = FreeCADGui.Selection.getSelectionEx() + + if not a2p_constraints.CircularEdgeConstraint.isValidSelection(): + return + + c = a2p_constraints.CircularEdgeConstraint(selection) + cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( + c.constraintObject, + 'createConstraint' + ) + FreeCADGui.Selection.clearSelection() + + def GetResources(self): + return { + 'Pixmap' : path_a2p + '/icons/a2p_CircularEdgeConstraint.svg' , + 'MenuText': 'Add circular edge connection', + 'ToolTip': a2p_constraints.CircularEdgeConstraint.getToolTip() + } + +FreeCADGui.addCommand('a2p_CircularEdgeConnection', a2p_CircularEdgeConnectionCommand()) +#============================================================================== +class a2p_AxialConstraintCommand: + def Activated(self): + selection = FreeCADGui.Selection.getSelectionEx() + + if not a2p_constraints.AxialConstraint.isValidSelection(): + return + + c = a2p_constraints.AxialConstraint(selection) + cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( + c.constraintObject, + 'createConstraint' + ) + FreeCADGui.Selection.clearSelection() + + def GetResources(self): + return { + 'Pixmap' : path_a2p + '/icons/a2p_AxialConstraint.svg', + 'MenuText': 'Add axial constraint', + 'ToolTip': a2p_constraints.AxialConstraint.getToolTip() + } + +FreeCADGui.addCommand('a2p_AxialConstraintCommand', a2p_AxialConstraintCommand()) +#============================================================================== +class a2p_AxisParallelConstraintCommand: + def Activated(self): + selection = FreeCADGui.Selection.getSelectionEx() + + if not a2p_constraints.AxisParallelConstraint.isValidSelection(): + return + + c = a2p_constraints.AxisParallelConstraint(selection) + cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( + c.constraintObject, + 'createConstraint' + ) + FreeCADGui.Selection.clearSelection() + + def GetResources(self): + return { + 'Pixmap' : ':/icons/a2p_AxisParallelConstraint.svg', + 'MenuText': 'Add axisParallel constraint', + 'ToolTip': a2p_constraints.AxisParallelConstraint.getToolTip() + } + +FreeCADGui.addCommand('a2p_AxisParallelConstraintCommand', a2p_AxisParallelConstraintCommand()) +#============================================================================== +class a2p_AxisPlaneParallelCommand: + def Activated(self): + selection = FreeCADGui.Selection.getSelectionEx() + + if not a2p_constraints.AxisPlaneParallelConstraint.isValidSelection(): + return + + c = a2p_constraints.AxisPlaneParallelConstraint(selection) + cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( + c.constraintObject, + 'createConstraint' + ) + FreeCADGui.Selection.clearSelection() + + def GetResources(self): + return { + 'Pixmap' : ':/icons/a2p_AxisPlaneParallelConstraint.svg', + 'MenuText': 'axisPlaneParallel constraint', + 'ToolTip': a2p_constraints.AxisPlaneParallelConstraint.getToolTip() + } + +FreeCADGui.addCommand('a2p_AxisPlaneParallelCommand', a2p_AxisPlaneParallelCommand()) +#============================================================================== +class a2p_PlanesParallelConstraintCommand: + def Activated(self): + selection = FreeCADGui.Selection.getSelectionEx() + + if not a2p_constraints.PlanesParallelConstraint.isValidSelection(): + return + + c = a2p_constraints.PlanesParallelConstraint(selection) + cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( + c.constraintObject, + 'createConstraint' + ) + FreeCADGui.Selection.clearSelection() + + def GetResources(self): + return { + 'Pixmap' : path_a2p + '/icons/a2p_PlanesParallelConstraint.svg', + 'MenuText': 'Add planesParallel constraint', + 'ToolTip': a2p_constraints.PlanesParallelConstraint.getToolTip() + } + +FreeCADGui.addCommand('a2p_PlanesParallelConstraintCommand', a2p_PlanesParallelConstraintCommand()) +#============================================================================== +class a2p_PlaneCoincidentConstraintCommand: + def Activated(self): + selection = FreeCADGui.Selection.getSelectionEx() + + if not a2p_constraints.PlaneConstraint.isValidSelection(): + return + + c = a2p_constraints.PlaneConstraint(selection) + cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( + c.constraintObject, + 'createConstraint' + ) + FreeCADGui.Selection.clearSelection() + + def GetResources(self): + return { + 'Pixmap' : path_a2p + '/icons/a2p_PlaneCoincidentConstraint.svg', + 'MenuText': 'Add plane constraint', + 'ToolTip': a2p_constraints.PlaneConstraint.getToolTip() + } + +FreeCADGui.addCommand('a2p_PlaneCoincidentConstraintCommand', a2p_PlaneCoincidentConstraintCommand()) +#============================================================================== +class a2p_AngledPlanesConstraintCommand: + def Activated(self): + selection = FreeCADGui.Selection.getSelectionEx() + + if not a2p_constraints.AngledPlanesConstraint.isValidSelection(): + return + + c = a2p_constraints.AngledPlanesConstraint(selection) + cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( + c.constraintObject, + 'createConstraint' + ) + FreeCADGui.Selection.clearSelection() + + + def GetResources(self): + return { + 'Pixmap' : path_a2p + '/icons/a2p_AngleConstraint.svg', + 'MenuText': 'angle between planes constraint', + 'ToolTip': a2p_constraints.AngledPlanesConstraint.getToolTip() + } + +FreeCADGui.addCommand('a2p_AngledPlanesConstraintCommand', a2p_AngledPlanesConstraintCommand()) + +#============================================================================== \ No newline at end of file diff --git a/a2p_constraints.py b/a2p_constraints.py index 4085c5ce..af3376d9 100644 --- a/a2p_constraints.py +++ b/a2p_constraints.py @@ -132,6 +132,11 @@ def calcInitialValues(self): @staticmethod def getToolTip(self): return 'Invalid Base Class BasicConstraint' + + @staticmethod + def isValidSelection(): + return True + #============================================================================== class PointIdentityConstraint(BasicConstraint): From 8f89cd638910c4f1777e4d5368372d4e40659c89 Mon Sep 17 00:00:00 2001 From: kbwbe Date: Wed, 2 Jan 2019 19:46:17 +0100 Subject: [PATCH 2/5] use command activation instead of selection gates --- a2p_constraintcommands.py | 157 +++++++++++++++++++++++++++++++++++--- a2p_constraints.py | 142 +++++++++++++++++++++++++++++++++- 2 files changed, 286 insertions(+), 13 deletions(-) diff --git a/a2p_constraintcommands.py b/a2p_constraintcommands.py index 9fc7758c..3f9fd36b 100644 --- a/a2p_constraintcommands.py +++ b/a2p_constraintcommands.py @@ -37,7 +37,11 @@ class a2p_PointIdentityConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.PointIdentityConstraint.isValidSelection(): + if not a2p_constraints.PointIdentityConstraint.isValidSelection(selection): + msg = ''' + To add a point Identity constraint select exactly two vertexes! + ''' + QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) return c = a2p_constraints.PointIdentityConstraint(selection) @@ -47,6 +51,11 @@ def Activated(self): ) FreeCADGui.Selection.clearSelection() + def IsActive(self): + return a2p_constraints.PointIdentityConstraint.isValidSelection( + FreeCADGui.Selection.getSelectionEx() + ) + def GetResources(self): return { 'Pixmap' : path_a2p + '/icons/a2p_PointIdentity.svg', @@ -61,8 +70,17 @@ class a2p_PointOnLineConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.PointOnLineConstraint.isValidSelection(): - return + if not a2p_constraints.PointOnLineConstraint.isValidSelection(selection): + msg = ''' + for PointOnLine constraint select in this order: + 1.) a vertex + 2.) a line (linear edge) + + Selection made: %s + ''' % printSelection(selection) + + QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) + return c = a2p_constraints.PointOnLineConstraint(selection) cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( @@ -71,6 +89,11 @@ def Activated(self): ) FreeCADGui.Selection.clearSelection() + def IsActive(self): + return a2p_constraints.PointOnLineConstraint.isValidSelection( + FreeCADGui.Selection.getSelectionEx() + ) + def GetResources(self): return { 'Pixmap' : path_a2p + '/icons/a2p_PointOnLineConstraint.svg', @@ -85,7 +108,16 @@ class a2p_PointOnPlaneConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.PointOnPlaneConstraint.isValidSelection(): + if not a2p_constraints.PointOnPlaneConstraint.isValidSelection(selection): + msg = ''' + for Point on Plane constraint select in this order: + 1.) a vertex or a center of a circle + 2.) a plane + + Selection made: %s + ''' % printSelection(selection) + + QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) return c = a2p_constraints.PointOnPlaneConstraint(selection) @@ -95,6 +127,11 @@ def Activated(self): ) FreeCADGui.Selection.clearSelection() + def IsActive(self): + return a2p_constraints.PointOnPlaneConstraint.isValidSelection( + FreeCADGui.Selection.getSelectionEx() + ) + def GetResources(self): return { 'Pixmap' : path_a2p + '/icons/a2p_PointOnPlaneConstraint.svg', @@ -108,7 +145,14 @@ class a2p_SphericalSurfaceConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.SphericalConstraint.isValidSelection(): + if not a2p_constraints.SphericalConstraint.isValidSelection(selection): + msg = ''' + To add a spherical surface constraint select two + spherical surfaces (or vertexs), + each from a different part. + Selection made: %s + ''' % printSelection(selection) + QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) return c = a2p_constraints.SphericalConstraint(selection) @@ -118,6 +162,11 @@ def Activated(self): ) FreeCADGui.Selection.clearSelection() + def IsActive(self): + return a2p_constraints.SphericalConstraint.isValidSelection( + FreeCADGui.Selection.getSelectionEx() + ) + def GetResources(self): return { 'Pixmap' : path_a2p + '/icons/a2p_SphericalSurfaceConstraint.svg', @@ -131,7 +180,13 @@ class a2p_CircularEdgeConnectionCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.CircularEdgeConstraint.isValidSelection(): + if not a2p_constraints.CircularEdgeConstraint.isValidSelection(selection): + msg = ''' + Please select two circular edges from different parts. + But election made is: + %s + ''' % printSelection(selection) + QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) return c = a2p_constraints.CircularEdgeConstraint(selection) @@ -141,6 +196,11 @@ def Activated(self): ) FreeCADGui.Selection.clearSelection() + def IsActive(self): + return a2p_constraints.CircularEdgeConstraint.isValidSelection( + FreeCADGui.Selection.getSelectionEx() + ) + def GetResources(self): return { 'Pixmap' : path_a2p + '/icons/a2p_CircularEdgeConstraint.svg' , @@ -154,7 +214,12 @@ class a2p_AxialConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.AxialConstraint.isValidSelection(): + if not a2p_constraints.AxialConstraint.isValidSelection(selection): + msg = ''' + To add an axial constraint select two cylindrical surfaces or two + straight lines, each from a different part. Selection made:%s + ''' % printSelection(selection) + QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) return c = a2p_constraints.AxialConstraint(selection) @@ -164,6 +229,11 @@ def Activated(self): ) FreeCADGui.Selection.clearSelection() + def IsActive(self): + return a2p_constraints.AxialConstraint.isValidSelection( + FreeCADGui.Selection.getSelectionEx() + ) + def GetResources(self): return { 'Pixmap' : path_a2p + '/icons/a2p_AxialConstraint.svg', @@ -177,7 +247,15 @@ class a2p_AxisParallelConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.AxisParallelConstraint.isValidSelection(): + if not a2p_constraints.AxisParallelConstraint.isValidSelection(selection): + msg = ''' + axisParallelConstraint requires a selection of: + - cylinderAxis or linearEdge on a part + - cylinderAxis or linearEdge on another part + Selection made: %s + ''' % printSelection(selection) + + QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) return c = a2p_constraints.AxisParallelConstraint(selection) @@ -187,6 +265,11 @@ def Activated(self): ) FreeCADGui.Selection.clearSelection() + def IsActive(self): + return a2p_constraints.AxisParallelConstraint.isValidSelection( + FreeCADGui.Selection.getSelectionEx() + ) + def GetResources(self): return { 'Pixmap' : ':/icons/a2p_AxisParallelConstraint.svg', @@ -200,7 +283,15 @@ class a2p_AxisPlaneParallelCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.AxisPlaneParallelConstraint.isValidSelection(): + if not a2p_constraints.AxisPlaneParallelConstraint.isValidSelection(selection): + msg = ''' + AxisPlaneParallel constraint requires a selection of + 1) linear edge or axis of cylinder + 2) a plane face + each on different objects. Selection made: + %s + ''' % printSelection(selection) + QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) return c = a2p_constraints.AxisPlaneParallelConstraint(selection) @@ -210,6 +301,11 @@ def Activated(self): ) FreeCADGui.Selection.clearSelection() + def IsActive(self): + return a2p_constraints.AxisPlaneParallelConstraint.isValidSelection( + FreeCADGui.Selection.getSelectionEx() + ) + def GetResources(self): return { 'Pixmap' : ':/icons/a2p_AxisPlaneParallelConstraint.svg', @@ -223,7 +319,15 @@ class a2p_PlanesParallelConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.PlanesParallelConstraint.isValidSelection(): + if not a2p_constraints.PlanesParallelConstraint.isValidSelection(selection): + msg = ''' + PlanesParallel constraint requires a selection of: + - exactly 2 planes on different parts + + Selection made: %s + ''' % printSelection(selection) + + QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) return c = a2p_constraints.PlanesParallelConstraint(selection) @@ -232,6 +336,11 @@ def Activated(self): 'createConstraint' ) FreeCADGui.Selection.clearSelection() + + def IsActive(self): + return a2p_constraints.PlanesParallelConstraint.isValidSelection( + FreeCADGui.Selection.getSelectionEx() + ) def GetResources(self): return { @@ -246,7 +355,15 @@ class a2p_PlaneCoincidentConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.PlaneConstraint.isValidSelection(): + if not a2p_constraints.PlaneConstraint.isValidSelection(selection): + msg = ''' + Plane constraint requires a selection of: + - exactly 2 planes on different parts + + Selection made: %s + ''' % printSelection(selection) + + QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) return c = a2p_constraints.PlaneConstraint(selection) @@ -256,6 +373,11 @@ def Activated(self): ) FreeCADGui.Selection.clearSelection() + def IsActive(self): + return a2p_constraints.PlaneConstraint.isValidSelection( + FreeCADGui.Selection.getSelectionEx() + ) + def GetResources(self): return { 'Pixmap' : path_a2p + '/icons/a2p_PlaneCoincidentConstraint.svg', @@ -269,7 +391,13 @@ class a2p_AngledPlanesConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.AngledPlanesConstraint.isValidSelection(): + if not a2p_constraints.AngledPlanesConstraint.isValidSelection(selection): + msg = ''' + Angle constraint requires a selection of 2 planes + each on different objects. Selection made: + %s + ''' % printSelection(selection) + QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) return c = a2p_constraints.AngledPlanesConstraint(selection) @@ -280,6 +408,11 @@ def Activated(self): FreeCADGui.Selection.clearSelection() + def IsActive(self): + return a2p_constraints.AngledPlanesConstraint.isValidSelection( + FreeCADGui.Selection.getSelectionEx() + ) + def GetResources(self): return { 'Pixmap' : path_a2p + '/icons/a2p_AngleConstraint.svg', diff --git a/a2p_constraints.py b/a2p_constraints.py index af3376d9..397c699f 100644 --- a/a2p_constraints.py +++ b/a2p_constraints.py @@ -134,7 +134,7 @@ def getToolTip(self): return 'Invalid Base Class BasicConstraint' @staticmethod - def isValidSelection(): + def isValidSelection(selection): return True @@ -159,6 +159,17 @@ def getToolTip(): 1.) select a vertex on a part 2.) select a vertex on another part ''' + + @staticmethod + def isValidSelection(selection): + validSelection = False + if len(selection) == 2: + s1, s2 = selection + if s1.ObjectName != s2.ObjectName: + if vertexSelected(s1) and vertexSelected(s2): + validSelection = True + return validSelection + #============================================================================== class PointOnLineConstraint(BasicConstraint): def __init__(self,selection): @@ -179,6 +190,17 @@ def getToolTip(): 1.) select a vertex from a part 2.) select a line (linear edge) on another part ''' + + @staticmethod + def isValidSelection(selection): + validSelection = False + if len(selection) == 2: + s1, s2 = selection + if s1.ObjectName != s2.ObjectName: + if vertexSelected(s1) and LinearEdgeSelected(s2): + validSelection = True + return validSelection + #============================================================================== class PointOnPlaneConstraint(BasicConstraint): def __init__(self,selection): @@ -210,6 +232,20 @@ def getToolTip(): 1.) select a vertex or a center of a circle 2.) select a plane on other part ''' + + @staticmethod + def isValidSelection(selection): + validSelection = False + if len(selection) == 2: + s1, s2 = selection + if s1.ObjectName != s2.ObjectName: + if ( + (vertexSelected(s1) or CircularEdgeSelected(s1)) and + planeSelected(s2) + ): + validSelection = True + return validSelection + #============================================================================== class CircularEdgeConstraint(BasicConstraint): def __init__(self,selection): @@ -242,6 +278,17 @@ def getToolTip(): 1.) select circular edge on first importPart 2.) select circular edge on other importPart ''' + + @staticmethod + def isValidSelection(selection): + validSelection = False + if len(selection) == 2: + s1, s2 = selection + if s1.ObjectName != s2.ObjectName: + if CircularEdgeSelected(s1) and CircularEdgeSelected(s2): + validSelection = True + return validSelection + #============================================================================== class AxialConstraint(BasicConstraint): def __init__(self,selection): @@ -275,6 +322,22 @@ def getToolTip(): 1.) Select cylindrical face or linear edge on a part 2.) Select cylindrical face or linear edge on another part ''' + + @staticmethod + def isValidSelection(selection): + + def ValidSelection(selectionExObj): + return cylindricalPlaneSelected(selectionExObj) \ + or LinearEdgeSelected(selectionExObj) + + validSelection = False + if len(selection) == 2: + s1, s2 = selection + if s1.ObjectName != s2.ObjectName: + if ValidSelection(s1) and ValidSelection(s2): + validSelection = True + return validSelection + #============================================================================== class AxisParallelConstraint(BasicConstraint): def __init__(self,selection): @@ -307,6 +370,20 @@ def getToolTip(): 1.) linearEdge or cylinderFace from a part 2.) linearEdge or cylinderFace from another part ''' + + @staticmethod + def isValidSelection(selection): + validSelection = False + if len(selection) == 2: + s1, s2 = selection + if s1.ObjectName != s2.ObjectName: + if ( + (LinearEdgeSelected(s1) or cylindricalPlaneSelected(s1)) and + (LinearEdgeSelected(s2) or cylindricalPlaneSelected(s2)) + ): + validSelection = True + return validSelection + #============================================================================== class AxisPlaneParallelConstraint(BasicConstraint): def __init__(self,selection): @@ -332,6 +409,20 @@ def getToolTip(): to a selected plane. The parts are not moved to be coincident. ''' + + @staticmethod + def isValidSelection(selection): + validSelection = False + if len(selection) == 2: + s1, s2 = selection + if s1.ObjectName != s2.ObjectName: + if ( + (LinearEdgeSelected(s1) or cylindricalPlaneSelected(s1)) and + planeSelected(s2) + ): + validSelection = True + return validSelection + #============================================================================== class PlanesParallelConstraint(BasicConstraint): def __init__(self,selection): @@ -366,6 +457,19 @@ def getToolTip(): 1.) select a plane on a part 2.) select a plane from another part ''' + + @staticmethod + def isValidSelection(selection): + validSelection = False + if len(selection) == 2: + s1, s2 = selection + if s1.ObjectName != s2.ObjectName: + #if not planeSelected(s1): #???? + # s2, s1 = s1, s2 #????? + if planeSelected(s1) and planeSelected(s2): + validSelection = True + return validSelection + #============================================================================== class PlaneConstraint(BasicConstraint): def __init__(self,selection): @@ -399,6 +503,19 @@ def getToolTip(): 1.) select a plane on a part 2.) select a plane from another part ''' + + @staticmethod + def isValidSelection(selection): + validSelection = False + if len(selection) == 2: + s1, s2 = selection + if s1.ObjectName != s2.ObjectName: + #if not planeSelected(s1): + # s2, s1 = s1, s2 + if planeSelected(s1) and planeSelected(s2): + validSelection = True + return validSelection + #============================================================================== class AngledPlanesConstraint(BasicConstraint): def __init__(self,selection): @@ -437,6 +554,17 @@ def getToolTip(): Better for that is using planesParallelConstraint. ''' + + @staticmethod + def isValidSelection(selection): + validSelection = False + if len(selection) == 2: + s1, s2 = selection + if s1.ObjectName != s2.ObjectName: + if ( planeSelected(s1) and planeSelected(s2)): + validSelection = True + return validSelection + #============================================================================== class SphericalConstraint(BasicConstraint): def __init__(self,selection): @@ -459,6 +587,18 @@ def getToolTip(): - spherical surface or vertex on a part - spherical surface or vertex on another part ''' + + @staticmethod + def isValidSelection(selection): + validSelection = False + if len(selection) == 2: + s1, s2 = selection + if s1.ObjectName != s2.ObjectName: + if ( vertexSelected(s1) or sphericalSurfaceSelected(s1)) \ + and ( vertexSelected(s2) or sphericalSurfaceSelected(s2)): + validSelection = True + return validSelection + #============================================================================== From de07876ede701abb0fffc01cd2f90995b2af8539 Mon Sep 17 00:00:00 2001 From: kbwbe Date: Thu, 3 Jan 2019 17:53:33 +0100 Subject: [PATCH 3/5] new preferences entry: showConstraintsOnToolbar --- GuiA2p/Resources/ui/a2p_prefs.ui | 18 ++++++++++++- InitGui.py | 43 +++++++++++++++++++------------- a2p_constraints.py | 33 ++++++++++++++++++++++++ a2plib.py | 1 + 4 files changed, 77 insertions(+), 18 deletions(-) diff --git a/GuiA2p/Resources/ui/a2p_prefs.ui b/GuiA2p/Resources/ui/a2p_prefs.ui index 72cdce14..26d0ef9a 100644 --- a/GuiA2p/Resources/ui/a2p_prefs.ui +++ b/GuiA2p/Resources/ui/a2p_prefs.ui @@ -196,10 +196,26 @@ 30 40 521 - 71 + 95 + + + + Show constraints on toolbar + + + true + + + showConstraintsOnToolbar + + + Mod/A2plus + + + diff --git a/InitGui.py b/InitGui.py index ac207d4e..22b8dca0 100644 --- a/InitGui.py +++ b/InitGui.py @@ -66,23 +66,32 @@ def Initialize(self): 'a2p_ConvertPart', 'a2p_editImportedPart', ] - constraintCommands = [ - 'a2p_ConstraintDialogCommand', - 'a2p_EditConstraintCommand', - 'a2p_PointIdentityConstraintCommand', - 'a2p_PointOnLineConstraintCommand', - 'a2p_PointOnPlaneConstraintCommand', - 'a2p_SphericalSurfaceConstraintCommand', - 'a2p_CircularEdgeConnection', - 'a2p_AxialConstraintCommand', - 'a2p_AxisParallelConstraintCommand', - 'a2p_AxisPlaneParallelCommand', - 'a2p_PlanesParallelConstraintCommand', - 'a2p_PlaneCoincidentConstraintCommand', - 'a2p_AngledPlanesConstraintCommand', - - 'a2p_DeleteConnectionsCommand', - ] + + if a2plib.SHOW_CONSTRAINTS_ON_TOOLBAR: + constraintCommands = [ + 'a2p_ConstraintDialogCommand', + 'a2p_EditConstraintCommand', + 'a2p_PointIdentityConstraintCommand', + 'a2p_PointOnLineConstraintCommand', + 'a2p_PointOnPlaneConstraintCommand', + 'a2p_SphericalSurfaceConstraintCommand', + 'a2p_CircularEdgeConnection', + 'a2p_AxialConstraintCommand', + 'a2p_AxisParallelConstraintCommand', + 'a2p_AxisPlaneParallelCommand', + 'a2p_PlanesParallelConstraintCommand', + 'a2p_PlaneCoincidentConstraintCommand', + 'a2p_AngledPlanesConstraintCommand', + + 'a2p_DeleteConnectionsCommand', + ] + else: + constraintCommands = [ + 'a2p_ConstraintDialogCommand', + 'a2p_EditConstraintCommand', + 'a2p_DeleteConnectionsCommand', + ] + solverCommands = [ 'a2p_SolverCommand', #'a2p_newSolverCommand', diff --git a/a2p_constraints.py b/a2p_constraints.py index 397c699f..c475de76 100644 --- a/a2p_constraints.py +++ b/a2p_constraints.py @@ -158,6 +158,9 @@ def getToolTip(): selection: 1.) select a vertex on a part 2.) select a vertex on another part + +Button gets active after +correct selection. ''' @staticmethod @@ -189,6 +192,9 @@ def getToolTip(): Add a pointOnLine constraint between two objects 1.) select a vertex from a part 2.) select a line (linear edge) on another part + +Button gets active after +correct selection. ''' @staticmethod @@ -231,6 +237,9 @@ def getToolTip(): Add a pointOnPlane constraint between two objects 1.) select a vertex or a center of a circle 2.) select a plane on other part + +Button gets active after +correct selection. ''' @staticmethod @@ -277,6 +286,9 @@ def getToolTip(): selection-hint: 1.) select circular edge on first importPart 2.) select circular edge on other importPart + +Button gets active after +correct selection. ''' @staticmethod @@ -321,6 +333,9 @@ def getToolTip(): Selection: 1.) Select cylindrical face or linear edge on a part 2.) Select cylindrical face or linear edge on another part + +Button gets active after +correct selection. ''' @staticmethod @@ -369,6 +384,9 @@ def getToolTip(): select: 1.) linearEdge or cylinderFace from a part 2.) linearEdge or cylinderFace from another part + +Button gets active after +correct selection. ''' @staticmethod @@ -408,6 +426,9 @@ def getToolTip(): This constraint adjusts an axis parallel to a selected plane. The parts are not moved to be coincident. + +Button gets active after +correct selection. ''' @staticmethod @@ -456,6 +477,9 @@ def getToolTip(): select: 1.) select a plane on a part 2.) select a plane from another part + +Button gets active after +correct selection. ''' @staticmethod @@ -502,6 +526,9 @@ def getToolTip(): select: 1.) select a plane on a part 2.) select a plane from another part + +Button gets active after +correct selection. ''' @staticmethod @@ -553,6 +580,9 @@ def getToolTip(): You could get strange results. Better for that is using planesParallelConstraint. + +Button gets active after +correct selection. ''' @staticmethod @@ -586,6 +616,9 @@ def getToolTip(): Selection options: - spherical surface or vertex on a part - spherical surface or vertex on another part + +Button gets active after +correct selection. ''' @staticmethod diff --git a/a2plib.py b/a2plib.py index 89859b65..160f220f 100644 --- a/a2plib.py +++ b/a2plib.py @@ -37,6 +37,7 @@ AUTOSOLVE_ENABLED = preferences.GetBool('autoSolve', True) RELATIVE_PATHES_ENABLED = preferences.GetBool('useRelativePathes',True) FORCE_FIXED_POSITION = preferences.GetBool('forceFixedPosition',True) +SHOW_CONSTRAINTS_ON_TOOLBAR= preferences.GetBool('showConstraintsOnToolbar',True) SAVED_TRANSPARENCY = [] From 49f1b5a39ea1aa6eed4fb4cd8af2fd73cde733a4 Mon Sep 17 00:00:00 2001 From: kbwbe Date: Thu, 3 Jan 2019 19:00:10 +0100 Subject: [PATCH 4/5] center constraint dialogs on FC mainwindow --- a2p_constraintDialog.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/a2p_constraintDialog.py b/a2p_constraintDialog.py index 411117f2..49c74cff 100644 --- a/a2p_constraintDialog.py +++ b/a2p_constraintDialog.py @@ -722,11 +722,19 @@ def onSpericalConstraintButton(self): self.manageConstraint() #============================================================================== -def getMoveDistToScreenCenter(widg): - w = QtGui.QApplication.desktop().width() - h = QtGui.QApplication.desktop().height() - center = QtCore.QPoint(w/2,h/2) - return center- widg.rect().center() +def getMoveDistToFcCenter(widg): + mw = FreeCADGui.getMainWindow() + fcFrame = QtGui.QDesktopWidget.geometry(mw) + x = fcFrame.x() + y = fcFrame.y() + width = fcFrame.width() + height = fcFrame.height() + + centerX = x + width/2 + centerY = y + height/2 + fcCenter = QtCore.QPoint(centerX,centerY) + + return fcCenter- widg.rect().center() #============================================================================== class a2p_ConstraintValuePanel(QtGui.QDockWidget): @@ -755,7 +763,7 @@ def __init__(self,constraintObject, mode): self.setFloating(True) self.activateWindow() self.setAllowedAreas(QtCore.Qt.NoDockWidgetArea) - self.move(getMoveDistToScreenCenter(self)) + self.move(getMoveDistToFcCenter(self)) a2plib.setConstraintEditorRef(self) @@ -788,7 +796,7 @@ def __init__(self): self.setFloating(True) self.activateWindow() self.setAllowedAreas(QtCore.Qt.NoDockWidgetArea) - self.move(getMoveDistToScreenCenter(self)) + self.move(getMoveDistToFcCenter(self)) a2plib.setConstraintDialogRef(self) # From d5c75ea0a26718763c3079a835855291c99e8b85 Mon Sep 17 00:00:00 2001 From: kbwbe Date: Thu, 3 Jan 2019 19:18:49 +0100 Subject: [PATCH 5/5] removed useless constraint selection warnings --- a2p_constraintcommands.py | 111 -------------------------------------- 1 file changed, 111 deletions(-) diff --git a/a2p_constraintcommands.py b/a2p_constraintcommands.py index 3f9fd36b..73072cde 100644 --- a/a2p_constraintcommands.py +++ b/a2p_constraintcommands.py @@ -37,13 +37,6 @@ class a2p_PointIdentityConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.PointIdentityConstraint.isValidSelection(selection): - msg = ''' - To add a point Identity constraint select exactly two vertexes! - ''' - QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return - c = a2p_constraints.PointIdentityConstraint(selection) cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( c.constraintObject, @@ -70,18 +63,6 @@ class a2p_PointOnLineConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.PointOnLineConstraint.isValidSelection(selection): - msg = ''' - for PointOnLine constraint select in this order: - 1.) a vertex - 2.) a line (linear edge) - - Selection made: %s - ''' % printSelection(selection) - - QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return - c = a2p_constraints.PointOnLineConstraint(selection) cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( c.constraintObject, @@ -108,18 +89,6 @@ class a2p_PointOnPlaneConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.PointOnPlaneConstraint.isValidSelection(selection): - msg = ''' - for Point on Plane constraint select in this order: - 1.) a vertex or a center of a circle - 2.) a plane - - Selection made: %s - ''' % printSelection(selection) - - QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return - c = a2p_constraints.PointOnPlaneConstraint(selection) cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( c.constraintObject, @@ -145,16 +114,6 @@ class a2p_SphericalSurfaceConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.SphericalConstraint.isValidSelection(selection): - msg = ''' - To add a spherical surface constraint select two - spherical surfaces (or vertexs), - each from a different part. - Selection made: %s - ''' % printSelection(selection) - QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return - c = a2p_constraints.SphericalConstraint(selection) cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( c.constraintObject, @@ -180,15 +139,6 @@ class a2p_CircularEdgeConnectionCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.CircularEdgeConstraint.isValidSelection(selection): - msg = ''' - Please select two circular edges from different parts. - But election made is: - %s - ''' % printSelection(selection) - QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return - c = a2p_constraints.CircularEdgeConstraint(selection) cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( c.constraintObject, @@ -214,14 +164,6 @@ class a2p_AxialConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.AxialConstraint.isValidSelection(selection): - msg = ''' - To add an axial constraint select two cylindrical surfaces or two - straight lines, each from a different part. Selection made:%s - ''' % printSelection(selection) - QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return - c = a2p_constraints.AxialConstraint(selection) cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( c.constraintObject, @@ -247,17 +189,6 @@ class a2p_AxisParallelConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.AxisParallelConstraint.isValidSelection(selection): - msg = ''' - axisParallelConstraint requires a selection of: - - cylinderAxis or linearEdge on a part - - cylinderAxis or linearEdge on another part - Selection made: %s - ''' % printSelection(selection) - - QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return - c = a2p_constraints.AxisParallelConstraint(selection) cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( c.constraintObject, @@ -283,17 +214,6 @@ class a2p_AxisPlaneParallelCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.AxisPlaneParallelConstraint.isValidSelection(selection): - msg = ''' - AxisPlaneParallel constraint requires a selection of - 1) linear edge or axis of cylinder - 2) a plane face - each on different objects. Selection made: - %s - ''' % printSelection(selection) - QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return - c = a2p_constraints.AxisPlaneParallelConstraint(selection) cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( c.constraintObject, @@ -319,17 +239,6 @@ class a2p_PlanesParallelConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.PlanesParallelConstraint.isValidSelection(selection): - msg = ''' - PlanesParallel constraint requires a selection of: - - exactly 2 planes on different parts - - Selection made: %s - ''' % printSelection(selection) - - QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return - c = a2p_constraints.PlanesParallelConstraint(selection) cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( c.constraintObject, @@ -355,17 +264,6 @@ class a2p_PlaneCoincidentConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.PlaneConstraint.isValidSelection(selection): - msg = ''' - Plane constraint requires a selection of: - - exactly 2 planes on different parts - - Selection made: %s - ''' % printSelection(selection) - - QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return - c = a2p_constraints.PlaneConstraint(selection) cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( c.constraintObject, @@ -391,15 +289,6 @@ class a2p_AngledPlanesConstraintCommand: def Activated(self): selection = FreeCADGui.Selection.getSelectionEx() - if not a2p_constraints.AngledPlanesConstraint.isValidSelection(selection): - msg = ''' - Angle constraint requires a selection of 2 planes - each on different objects. Selection made: - %s - ''' % printSelection(selection) - QtGui.QMessageBox.information( QtGui.QApplication.activeWindow(), "Incorrect Usage", msg) - return - c = a2p_constraints.AngledPlanesConstraint(selection) cvp = a2p_constraintDialog.a2p_ConstraintValuePanel( c.constraintObject,