示例#1
0
def removeConstraint( constraint ):
    'required as constraint.Proxy.onDelete only called when deleted through GUI'
    doc = constraint.Document
    debugPrint(2, "removing constraint %s" % constraint.Name )
    if constraint.ViewObject != None: #do not this check is actually nessary ...
        constraint.ViewObject.Proxy.onDelete( constraint.ViewObject, None )
    doc.removeObject( constraint.Name )
示例#2
0
def removeConstraint(constraint):
    'required as constraint.Proxy.onDelete only called when deleted through GUI'
    doc = constraint.Document
    debugPrint(2, "removing constraint %s" % constraint.Name)
    if constraint.ViewObject != None:  #do not this check is actually nessary ...
        constraint.ViewObject.Proxy.onDelete(constraint.ViewObject, None)
    doc.removeObject(constraint.Name)
示例#3
0
 def _test_file( self, testFile_basename, solution = None ):
     testFile = os.path.join( test_assembly_path, testFile_basename + '.fcstd' )
     debugPrint(1, testFile_basename )
     stats.n_attempted += 1
     #if testFile == 'tests/testAssembly11-Pipe_assembly.fcstd':
     #    print('Skipping known fail')
     #    continue
     doc =  FreeCAD.open(testFile)
     t_start_solver = time.time()
     xOpt = solveConstraints( doc, solver_name = 'newton_solver_slsqp', use_cache = self.use_cache, showFailureErrorDialog=False )
     if solution:
         self.check_solution( xOpt, solution )
     stats.t_solver += time.time() - t_start_solver
     assert not self.use_cache
     if not xOpt is None:
         stats.n_solved += 1
     FreeCAD.closeDocument( doc.Name )
     debugPrint(1,'\n\n\n')
     return xOpt
示例#4
0
 def _test_file( self, testFile_basename, solution = None ):
     testFile = os.path.join( test_assembly_path, testFile_basename + '.fcstd' )
     debugPrint(1, testFile_basename )
     stats.n_attempted += 1
     #if testFile == 'tests/testAssembly11-Pipe_assembly.fcstd':
     #    print('Skipping known fail')
     #    continue
     doc =  FreeCAD.open(testFile)
     t_start_solver = time.time()
     constraintSystem = solveConstraints( doc, solver_name = 'dof_reduction_solver', use_cache = self.use_cache, showFailureErrorDialog=False )
     if solution:
         self.check_solution( constraintSystem, solution )
     stats.t_solver += time.time() - t_start_solver
     if  self.use_cache:
         debugPrint(1,'\n\n')
         X_org = constraintSystem.variableManager.X
         t_start_cache = time.time()
         #cache.debugMode = 1
         constraintSystem = solveConstraints( doc, solver_name = 'dof_reduction_solver', use_cache =  self.use_cache )
         self.assertTrue(
             numpy.allclose( X_org , constraintSystem.variableManager.X ),
             'Cache solution differs from originial solution: %s != %s' % ( X_org , constraintSystem.variableManager.X )
         )
         #cache.debugMode = 0
         stats.t_cache += time.time() - t_start_cache
         constraintSystem.update()
     stats.n_solved += 1
     FreeCAD.closeDocument( doc.Name )
     debugPrint(1,'\n\n\n')
示例#5
0
 def _test_file( self, testFile_basename, solution = None ):
     testFile = os.path.join( test_assembly_path, testFile_basename + '.fcstd' )
     debugPrint(1, testFile_basename )
     stats.n_attempted += 1
     #if testFile == 'tests/testAssembly11-Pipe_assembly.fcstd':
     #    print('Skipping known fail')
     #    continue
     doc =  FreeCAD.open(testFile)
     t_start_solver = time.time()
     constraintSystem = solveConstraints( doc, solver_name = 'dof_reduction_solver', use_cache = self.use_cache )
     if solution:
         self.check_solution( constraintSystem, solution )
     stats.t_solver += time.time() - t_start_solver
     if  self.use_cache:
         debugPrint(1,'\n\n')
         X_org = constraintSystem.variableManager.X
         t_start_cache = time.time()
         #cache.debugMode = 1
         constraintSystem = solveConstraints( doc, solver_name = 'dof_reduction_solver', use_cache =  self.use_cache )
         self.assertTrue(
             numpy.allclose( X_org , constraintSystem.variableManager.X ),
             'Cache solution differs from originial solution: %s != %s' % ( X_org , constraintSystem.variableManager.X )
         )
         #cache.debugMode = 0
         stats.t_cache += time.time() - t_start_cache
         constraintSystem.update()
     stats.n_solved += 1
     debugPrint(1,'\n\n\n')
示例#6
0
 def tearDownClass(cls):
     debugPrint(0,'\n------------------------------------------')
     debugPrint(0,'  dof_reduction_solver passed %i/%i tests' % ( stats.n_solved, stats.n_attempted ) )
     debugPrint(0,'    time solver:            %3.2f s' % stats.t_solver )
     debugPrint(0,'    time cached solutions:  %3.2f s' % stats.t_cache )
     debugPrint(0,'    total running time:     %3.2f s' % (time.time() - stats.t_start) )
     debugPrint(0,'------------------------------------------')
示例#7
0
def findBaseObject( doc, objectNames  ):
    debugPrint( 4,'solveConstraints: searching for fixed object to begin solving constraints from.' )
    fixed = [ getattr( doc.getObject( name ), 'fixedPosition', False ) for name in objectNames ]
    if sum(fixed) > 0:
        return objectNames[ fixed.index(True) ]
    if sum(fixed) == 0:
        debugPrint( 1, 'It is recommended that the assembly 2 module is used with parts imported using the assembly 2 module.')
        debugPrint( 1, 'This allows for part updating, parts list support, object copying (shift + assembly2 move) and also tells the solver which objects to treat as fixed.')
        debugPrint( 1, 'since no objects have the fixedPosition attribute, fixing the postion of the first object in the first constraint')
        debugPrint( 1, 'assembly 2 solver: assigning %s a fixed position' % objectNames[0])
        debugPrint( 1, 'assembly 2 solver: assigning %s, %s a fixed position' % (objectNames[0], doc.getObject(objectNames[0]).Label))
        return objectNames[0]
示例#8
0
 def tearDownClass(cls):
     debugPrint(0, '\n------------------------------------------')
     debugPrint(
         0, '  dof_reduction_solver passed %i/%i tests' %
         (stats.n_solved, stats.n_attempted))
     debugPrint(0, '    time solver:            %3.2f s' % stats.t_solver)
     debugPrint(0, '    time cached solutions:  %3.2f s' % stats.t_cache)
     debugPrint(
         0, '    total running time:     %3.2f s' %
         (time.time() - stats.t_start))
     debugPrint(0, '------------------------------------------')
示例#9
0
def findBaseObject(doc, objectNames):
    debugPrint(
        4,
        'solveConstraints: searching for fixed object to begin solving constraints from.'
    )
    fixed = [
        getattr(doc.getObject(name), 'fixedPosition', False)
        for name in objectNames
    ]
    if sum(fixed) > 0:
        return objectNames[fixed.index(True)]
    if sum(fixed) == 0:
        debugPrint(
            1,
            'It is recommended that the assembly 2 module is used with parts imported using the assembly 2 module.'
        )
        debugPrint(
            1,
            'This allows for part updating, parts list support, object copying (shift + assembly2 move) and also tells the solver which objects to treat as fixed.'
        )
        debugPrint(
            1,
            'since no objects have the fixedPosition attribute, fixing the postion of the first object in the first constraint'
        )
        debugPrint(
            1, 'assembly 2 solver: assigning %s a fixed position' %
            objectNames[0])
        debugPrint(
            1, 'assembly 2 solver: assigning %s, %s a fixed position' %
            (objectNames[0], doc.getObject(objectNames[0]).Label))
        return objectNames[0]