Skip to content

Commit

Permalink
Merge pull request #382 from kbwbe/temp
Browse files Browse the repository at this point in the history
added a tool for finding conflicting constraints
  • Loading branch information
kbwbe authored Apr 26, 2020
2 parents 19d8a3b + defc48a commit 25e590e
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 21 deletions.
6 changes: 4 additions & 2 deletions InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
__title__ = 'A2plus assembly Workbench - InitGui file'
__author__ = 'kbwbe'

A2P_VERSION = 'V0.4.46c'
A2P_VERSION = 'V0.4.47'

import FreeCAD
import FreeCADGui
Expand Down Expand Up @@ -67,6 +67,7 @@ def Initialize(self):
import a2p_constraintcommands
import a2p_bom # bom == bill of materials == partslist
import a2p_constraintServices
import a2p_searchConstraintConflicts

if a2plib.getRecursiveUpdateEnabled():
partCommands = [
Expand Down Expand Up @@ -127,7 +128,8 @@ def Initialize(self):
'a2p_SolverCommand',
'a2p_ToggleAutoSolveCommand',
'a2p_FlipConstraintDirectionCommand',
'a2p_Show_Hierarchy_Command'
'a2p_Show_Hierarchy_Command',
'a2p_SearchConstraintConflictsCommand'
]
viewCommands = [
'a2p_isolateCommand',
Expand Down
8 changes: 4 additions & 4 deletions a2p_Resources2.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions a2p_Resources3.py

Large diffs are not rendered by default.

104 changes: 104 additions & 0 deletions a2p_searchConstraintConflicts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#***************************************************************************
#* *
#* Copyright (c) 2020 kbwbe *
#* *
#* Based on Work of Dan Miel (Thank you) *
#* *
#* 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
import FreeCADGui
from PySide import QtGui

import a2plib
import a2p_solversystem

#==============================================================================
class a2p_SearchConstraintConflictsCommand:
'''
Search conflicting constraints by solving them one after each other.
'''
def Activated(self):
doc = FreeCAD.activeDocument()

workList = []
constraints = [ obj for obj in doc.Objects if 'ConstraintInfo' in obj.Content]

if len(constraints) == 0:
flags = QtGui.QMessageBox.StandardButton.Yes
QtGui.QMessageBox.information(
QtGui.QApplication.activeWindow(),
u'Searching for conflicting constraints',
u'There are no a2p constraints within this document.',
flags
)
return

for c in constraints:
workList.append(c)
solved = a2p_solversystem.solveConstraints(doc,matelist = workList, showFailMessage=False)
if solved == False:
cMirrorName = c.ViewObject.Proxy.mirror_name
cmirror = doc.getObject(cMirrorName)
ob1 = doc.getObject(c.Object1)
ob2 = doc.getObject(c.Object2)
message = \
u'''
The following constraint-pair is conflicting
with previously defined constraints:
constraint : {}
with mirror: {}
The constraint-pair belongs to the objects:
object1: {}
object2: {}
Do you want to delete this constraint-pair?
'''.format(
c.Label,
cmirror.Label,
ob1.Label,
ob2.Label
)
flags = QtGui.QMessageBox.StandardButton.Yes | QtGui.QMessageBox.StandardButton.No
response = QtGui.QMessageBox.information(
QtGui.QApplication.activeWindow(),
u'Searching for conflicting constraints',
message,
flags
)
if response == QtGui.QMessageBox.Yes:
a2plib.removeConstraint(c)

def IsActive(self):
if FreeCAD.activeDocument() is None: return False
return True

def GetResources(self):
return {
'Pixmap' : a2plib.pathOfModule()+'/icons/a2p_SearchConstraintConflicts.svg',
'MenuText': 'Conflictfinder tool: Search conflicting constraints',
'ToolTip': 'Conflictfinder tool: Search conflicting constraints by solving them one after another'
}
FreeCADGui.addCommand('a2p_SearchConstraintConflictsCommand', a2p_SearchConstraintConflictsCommand())
#==============================================================================


23 changes: 12 additions & 11 deletions a2p_solversystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def solveAccuracySteps(self,doc, matelist=None):

return systemSolved

def solveSystem(self,doc,matelist=None):
def solveSystem(self,doc,matelist=None, showFailMessage=True):
if not a2plib.SIMULATION_STATE:
Msg( "\n===== Start Solving System ====== \n" )

Expand All @@ -485,17 +485,18 @@ def solveSystem(self,doc,matelist=None):

else: # a2plib.SIMULATION_STATE == False
self.status = "unsolved"
Msg( "===== Could not solve system ====== \n" )
msg = \
if showFailMessage == True:
Msg( "===== Could not solve system ====== \n" )
msg = \
'''
Constraints inconsistent. Cannot solve System.
Please delete your last created constraint !
Please run the conflict finder tool !
'''
QtGui.QMessageBox.information(
QtGui.QApplication.activeWindow(),
"Constraint mismatch",
msg
)
QtGui.QMessageBox.information(
QtGui.QApplication.activeWindow(),
"Constraint mismatch",
msg
)
return systemSolved

def checkForUnmovedParts(self):
Expand Down Expand Up @@ -662,10 +663,10 @@ def solutionToParts(self,doc):
rig.applySolution(doc, self);

#------------------------------------------------------------------------------
def solveConstraints( doc, cache=None, useTransaction = True, matelist=None):
def solveConstraints( doc, cache=None, useTransaction = True, matelist=None, showFailMessage=True):
if useTransaction: doc.openTransaction("a2p_systemSolving")
ss = SolverSystem()
systemSolved = ss.solveSystem(doc, matelist )
systemSolved = ss.solveSystem(doc, matelist, showFailMessage )
if useTransaction: doc.commitTransaction()
a2plib.unTouchA2pObjects()
return systemSolved
Expand Down
Loading

0 comments on commit 25e590e

Please # to comment.