Skip to content

Commit

Permalink
Merge pull request #145 from kbwbe/devel
Browse files Browse the repository at this point in the history
modified autosolve, constraint dialogs store position
  • Loading branch information
kbwbe authored Jan 7, 2019
2 parents 2d659b7 + 8fb6256 commit 359ddcf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class a2pWorkbench (Workbench):
def __init__(self):
import a2plib
self.__class__.Icon = a2plib.pathOfModule() + "/icons/a2p_workbench.svg"
self.__class__.MenuText = 'A2plus'
self.__class__.MenuText = 'A2plus V0.2.4'
self.__class__.ToolTip = 'An other assembly workbench for FreeCAD'

def Initialize(self):
Expand Down
70 changes: 56 additions & 14 deletions a2p_constraintDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import a2p_constraints


CONSTRAINT_DIALOG_STORED_POSITION = QtCore.QPoint(-1,-1)

#==============================================================================
class a2p_ConstraintValueWidget(QtGui.QWidget):

Expand Down Expand Up @@ -722,19 +724,23 @@ def onSpericalConstraintButton(self):
self.manageConstraint()

#==============================================================================
def getMoveDistToFcCenter(widg):
mw = FreeCADGui.getMainWindow()
fcFrame = QtGui.QDesktopWidget.geometry(mw)
x = fcFrame.x()
y = fcFrame.y()
width = fcFrame.width()
height = fcFrame.height()
def getMoveDistToStoredPosition(widg):
if CONSTRAINT_DIALOG_STORED_POSITION == QtCore.QPoint(-1,-1):
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)

centerX = x + width/2
centerY = y + height/2
fcCenter = QtCore.QPoint(centerX,centerY)

return fcCenter- widg.rect().center()
return fcCenter- widg.rect().center()
else:
#center = QtCore.QPoint(centerX,centerY)
return CONSTRAINT_DIALOG_STORED_POSITION - widg.rect().center()
#==============================================================================
class a2p_ConstraintValuePanel(QtGui.QDockWidget):

Expand Down Expand Up @@ -763,16 +769,39 @@ def __init__(self,constraintObject, mode):
self.setFloating(True)
self.activateWindow()
self.setAllowedAreas(QtCore.Qt.NoDockWidgetArea)
self.move(getMoveDistToFcCenter(self))
self.move(getMoveDistToStoredPosition(self))

a2plib.setConstraintEditorRef(self)
if mode == 'createConstraint':
if a2plib.getAutoSolveState():
doc = FreeCAD.activeDocument()
if doc != None:
solveConstraints(doc)

def storeWindowCenterPosition(self):
# ConstraintDialog has Priority on storing its position
if a2plib.getConstraintDialogRef() != None:
return
# self.rect().center() does not work here somehow
frame = QtGui.QDockWidget.geometry(self)
x = frame.x()
y = frame.y()
width = frame.width()
height = frame.height()
centerX = x + width/2
centerY = y + height/2

global CONSTRAINT_DIALOG_STORED_POSITION
CONSTRAINT_DIALOG_STORED_POSITION = QtCore.QPoint(centerX,centerY)

def onAcceptConstraint(self):
self.storeWindowCenterPosition()
self.Accepted.emit()
a2plib.setConstraintEditorRef(None)
self.deleteLater()

def onDeleteConstraint(self):
self.storeWindowCenterPosition()
self.Deleted.emit()
a2plib.setConstraintEditorRef(None)
self.deleteLater()
Expand All @@ -796,7 +825,7 @@ def __init__(self):
self.setFloating(True)
self.activateWindow()
self.setAllowedAreas(QtCore.Qt.NoDockWidgetArea)
self.move(getMoveDistToFcCenter(self))
self.move(getMoveDistToStoredPosition(self))

a2plib.setConstraintDialogRef(self)
#
Expand All @@ -812,6 +841,19 @@ def onTimer(self):
if not self.isVisible():
self.show()
self.resize(200,250)
# calculate window center position and save it
# self.rect().center() does not work here somehow
frame = QtGui.QDockWidget.geometry(self)
x = frame.x()
y = frame.y()
width = frame.width()
height = frame.height()
centerX = x + width/2
centerY = y + height/2

global CONSTRAINT_DIALOG_STORED_POSITION
CONSTRAINT_DIALOG_STORED_POSITION = QtCore.QPoint(centerX,centerY)

self.timer.start(100)

def closeEvent(self,event):
Expand Down

0 comments on commit 359ddcf

Please sign in to comment.