def set_sweep_shape(self, sweepShape='rectangle', simType='verifier'): sys.path.append(self.pluginPath) print self.pluginPath print os.getcwd() from Utilities import ini_worker reload(ini_worker) if simType == 'verifier': section_params = ini_worker.get_section_from_ini( self.INI_CONFIG, 'SIMULATION') for key, value in section_params.iteritems(): if key == 'sweepShape': print 'SIMULATION SWEEP SHAPE SWITCHED TO ' + sweepShape ini_worker.write_to_section(self.INI_CONFIG, 'SIMULATION', 'sweepShape', sweepShape) elif simType == 'MachSim': section_params = ini_worker.get_section_from_ini( self.INI_MachSim, 'startup') print section_params for key, value in section_params.iteritems(): if key == 'tpSweepShape': print 'SIMULATION SWEEP SHAPE SWITCHED TO ' + sweepShape ini_worker.write_to_section(self.INI_MachSim, 'startup', 'tpSweepShape', sweepShape)
def proof_comments(self): """ :return: """ print bcolors.BOLD + '\nMATCHING COMMENTS' + bcolors.END for section in self.section_list_orig: self.section_param_orig[section] = ini_worker.get_section_from_ini( self.config_orig, section) self.section_comments_orig[ section] = ini_worker.get_comments_by_section( self.config_orig, section) for section in self.section_list_test: self.section_param_test[section] = ini_worker.get_section_from_ini( self.config_test, section) self.section_comments_test[ section] = ini_worker.get_comments_by_section( self.config_test, section) for key_section, comments_dict in self.section_comments_test.iteritems( ): print 'CHECKING: ' + key_section if len(comments_dict) == 0: print bcolors.RED + 'SECTION ' + key_section + ': COMMENT -> MISSING ' + bcolors.END else: pass
def refresh_UI(self): for section in self.section_list: section_params = ini_worker.get_section_from_ini(self.configFile, section) for param, value in section_params.iteritems(): if param == 'hideSection': hideSection = value if not hideSection: for param, value in section_params.iteritems(): if param == 'create': if int(value): keys = self.param_dict[section].keys() self.param_dict[section][keys[0]][1]['headline'].SetForegroundColour(UI.TOK['FG']) self.param_dict[section][keys[0]][1]['headline'].Hide() self.param_dict[section][keys[0]][1]['headline'].Show() else: keys = self.param_dict[section].keys() self.param_dict[section][keys[0]][1]['headline'].SetForegroundColour(UI.TERROR['FG']) self.param_dict[section][keys[0]][1]['headline'].Hide() self.param_dict[section][keys[0]][1]['headline'].Show() if param not in self.black_list: if self.param_dict[section][param][0]['ebox'][1] != value: self.param_dict[section][param][0]['ebox'][0].SetForegroundColour(UI.ECOLOR2CHANGE['FG']) # set color self.param_dict[section][param][0]['ebox'][0].SetBackgroundColour(UI.ECOLOR2CHANGE['BG']) self.param_dict[section][param][0]['ebox'][0].SetValue(str(value)) self.param_dict[section][param][0]['ebox'][1] = value if self.section_EC_stat[section]: self.param_dict[section][param][0]['ebox'][0].Hide() self.param_dict[section][param][0]['ebox'][0].Show()
def getSimulationPrecision(fileName): sim_params = ini_worker.get_section_from_ini(fileName, 'SIMULATION') if 'precision' in sim_params: return sim_params['precision'] else: return None
def set_sweep_shape(self, sweepShape='rectangle'): sys.path.append(self.pluginPath) print self.pluginPath print os.getcwd() from Utilities import ini_worker reload(ini_worker) section_params = ini_worker.get_section_from_ini(self.INI_CONFIG, 'SIMULATION') for key, value in section_params.iteritems(): if key == 'sweepShape': print 'SIMULATION SWEEP SHAPE SWITCHED TO ' + sweepShape ini_worker.write_to_section(self.INI_CONFIG, 'SIMULATION', 'sweepShape', sweepShape)
def refresh_UI(self): for section in self.section_list: section_params = ini_worker.get_section_from_ini( self.configFile, section) for param, value in section_params.iteritems(): if param == 'hideSection': hideSection = value if not hideSection: for param, value in section_params.iteritems(): if param == 'create': if int(value): keys = self.param_dict[section].keys() self.param_dict[section][ keys[0]][1]['headline'].SetForegroundColour( UI.TOK['FG']) self.param_dict[section][ keys[0]][1]['headline'].Hide() self.param_dict[section][ keys[0]][1]['headline'].Show() else: keys = self.param_dict[section].keys() self.param_dict[section][ keys[0]][1]['headline'].SetForegroundColour( UI.TERROR['FG']) self.param_dict[section][ keys[0]][1]['headline'].Hide() self.param_dict[section][ keys[0]][1]['headline'].Show() if param not in self.black_list: if self.param_dict[section][param][0]['ebox'][ 1] != value: self.param_dict[section][param][0][ 'ebox'][0].SetForegroundColour( UI.ECOLOR2CHANGE['FG']) # set color self.param_dict[section][param][0]['ebox'][ 0].SetBackgroundColour(UI.ECOLOR2CHANGE['BG']) self.param_dict[section][param][0]['ebox'][ 0].SetValue(str(value)) self.param_dict[section][param][0]['ebox'][ 1] = value if self.section_EC_stat[section]: self.param_dict[section][param][0]['ebox'][ 0].Hide() self.param_dict[section][param][0]['ebox'][ 0].Show()
def switch(self): sys.path.append(self.pluginPath) from Utilities import ini_worker reload(ini_worker) section_params = ini_worker.get_section_from_ini(self.INI_CONFIG, self.feature) for key, value in section_params.iteritems(): if key == "create": if int(value) == 0: print self.feature + " SWITCHED TO ON" ini_worker.write_to_section(self.INI_CONFIG, self.feature, "create", 1) else: print self.feature + " SWITCHED TO OFF" ini_worker.write_to_section(self.INI_CONFIG, self.feature, "create", 0)
def switch(self): sys.path.append(self.pluginPath) from Utilities import ini_worker reload(ini_worker) section_params = ini_worker.get_section_from_ini( self.INI_CONFIG, self.feature) for key, value in section_params.iteritems(): if key == 'create': if int(value) == 0: print self.feature + ' SWITCHED TO ON' ini_worker.write_to_section(self.INI_CONFIG, self.feature, 'create', 1) else: print self.feature + ' SWITCHED TO OFF' ini_worker.write_to_section(self.INI_CONFIG, self.feature, 'create', 0)
def getSimulationPrecision(fileName): sim_params = ini_worker.get_section_from_ini(fileName, "SIMULATION") return sim_params["precision"]
import sys sys.path.append( r'C:\Users\ModuleWoks\Documents\Development\GitRep\gcode2cutsim') import rhinoscriptsyntax as rs from Utilities import ini_worker reload(ini_worker) INI_CONFIG = r'C:\StoreDaily\Mesh.ini' section_params = ini_worker.get_section_from_ini(INI_CONFIG, 'BRIM') for key, value in section_params.iteritems(): if key == 'create': if int(value) == 0: print 'BRIM SWITCHED TO ON' ini_worker.write_to_section(INI_CONFIG, 'BRIM', 'create', 1) else: print 'BRIM SWITCHED TO OFF' ini_worker.write_to_section(INI_CONFIG, 'BRIM', 'create', 0)
def get_simulation_data(self): sim_params = ini_worker.get_section_from_ini(self.configFile, 'SIMULATION') return sim_params
import sys sys.path.append(r'C:\Users\ModuleWoks\Documents\Development\GitRep\gcode2cutsim') import rhinoscriptsyntax as rs from Utilities import ini_worker reload(ini_worker) INI_CONFIG = r'C:\StoreDaily\Mesh.ini' section_params = ini_worker.get_section_from_ini(INI_CONFIG, 'BRIM') for key, value in section_params.iteritems(): if key == 'create': if int(value) == 0: print 'BRIM SWITCHED TO ON' ini_worker.write_to_section(INI_CONFIG, 'BRIM', 'create', 1) else: print 'BRIM SWITCHED TO OFF' ini_worker.write_to_section(INI_CONFIG, 'BRIM', 'create', 0)
def main(): """Main module admins the additional arguments passed with 3DPrinter.exe Here is decided if test stage will be executed or just a single STL file is processed. Also all exceptions when passing wrong commands are handled here. """ _TS_LOGGER = G2CLogging.G2CLogging() # start logger _ABS_TEST_FODLER = r'\\OFFICE-AACHEN\projects\07_Products\06_3D-Printing\TestStage' _TS_LOGGER.wlog('INFO', 'WORKING DIRECTORY: ' + _ABS_TEST_FODLER) _COMMAND_LIST_TEST_STAGE = [{'TS': {'TS': False, 'MT': True, 'GT': False, 'TF': True }}, ] _COMMAND_LIST_SINGLE_FILE = [{'STL': {'STL': True, 'SIM': True}}, {'SIM': {'P': True}}] _H = help.helper() TS = TestStage() print '\n' + bcolors.UNDERLINE + bcolors.BOLD + 'MW 3DPRINTER MULTIOPERATOR ... ' + bcolors.END print 'INIT ...' + '\n' if len(sys.argv) == 1: # this is a default case with no passed command print bcolors.WARNING + 'No STL passed. Starting with STL file name in config.ini' + bcolors.END section_dict = get_section_from_ini('bin\\3DPrintModule\\config.ini', 'MESH') # read all parameters related to MESH TS.start3DPrintJob(STL_file=section_dict['fileName']) # not necessary to pass over stl. default is None else: bool_list = ['-' in s for s in sys.argv] # proof if commands are complete or if a command is given if bool_list[1]: # we expect an command with prefix '-' here command_dict = {} if sys.argv[1][1:] == 'TS': # this is test stage if len(sys.argv) > 2: for i in range(2, len(sys.argv)): # check command list TS_DICT = _COMMAND_LIST_TEST_STAGE[0]['TS'] if sys.argv[i][1:] in TS_DICT: if TS_DICT[sys.argv[i][1:]]: if len(sys.argv)-1 > i: if sys.argv[i+1][0] == '-': print 'Input for parameter ' + sys.argv[i] + ' expected.' return else: # command_dict.append(sys.argv[i][1:] + '=' + sys.argv[i+1]) command_dict[sys.argv[i][1:]] = sys.argv[i+1] else: print 'Input for parameter ' + sys.argv[i] + ' expected.' return else: # command_dict.append(sys.argv[i][1:] + '=True') command_dict[sys.argv[i][1:]] = True TM = thread_manager(TF=_ABS_TEST_FODLER, command_dict=command_dict) TM.controller() else: # seems there is only one command. So start test stage with default parameters TM = thread_manager(TF=_ABS_TEST_FODLER) TM.controller() elif sys.argv[1][1:] == 'STL': # process a single STL for i in range(1, len(sys.argv)): print sys.argv[i] # if sys.argv[i][0] == '-': # if len(sys.argv[i]) > 1: # if sys.argv[i][1:] == 'TS': # file_list = os.listdir(_RELATIVEFOLDERTESTFILES) # get directory list # test_file_list = [] # for i in file_list: # if i.find('.stl') != -1: # test_file_list.append(i) # # print '\n' + bcolors.BOLD + 'TESTNG STL SET:' + '-'*60 + '\n' + bcolors.END # # for i, j in zip(test_file_list, range(len(test_file_list)) ): # print bcolors.DARKGREY + '+-> ' + str(j) + ' ' + i + bcolors.END # # print '-'*60 + '\n' # # jj = 0 # while 1: # if (threading.activeCount() - 1) <= _MAXTHREADS: # i = test_file_list[jj] # message = '\n' + 'TS<=: Starting test ' + str(jj + 1) + ' of ' + str(len(test_file_list)) + \ # ' with: ' + i + ' - Running threads [' + str(threading.activeCount()-1) + ']' # print bcolors.UNDERLINE + bcolors.BOLD + message + bcolors.END + '\n' # TestStage(path=_RELATIVEFOLDERTESTFILES, fileName=i).start() # jj += 1 # if jj >= len(test_file_list): # break # # print bcolors.BOLD + '<ALL THREADS AND TESTING STAGES RUNNING>' + bcolors.END # # elif sys.argv[i][1:] == 'SF': # SF for single file [STL] # # we passed a storage place to a stl file # if len(sys.argv) == 3: # if not os.path.isfile(sys.argv[2]): # print bcolors.FAIL + 'No such STL file -> "' + str(sys.argv[2]) + '" ... Please proof INPUT' + bcolors.END # else: # print 'Processing >> ' + sys.argv[2] + '\n' # TestStage(sys.argv[2]).start3DPrintJob(sys.argv[2]) # else: # print bcolors.RED + 'Please provide STL file' + bcolors.END # # else: # print bcolors.RED + 'No known command.' + bcolors.END + '\n' # _H.print_help() # else: # print bcolors.RED + 'No command.' + bcolors.END + '\n' # _H.print_help() # else: # print bcolors.RED + 'If you want to pass a command use the - operator with following commandline' \ # + bcolors.END + '\n' # _H.print_help() print bcolors.DARKGREY +'TS<=:DONE' + bcolors.END
import sys sys.path.append(r'C:\Users\ModuleWoks\Documents\Development\GitRep\gcode2cutsim') import rhinoscriptsyntax as rs from Utilities import ini_worker reload(ini_worker) INI_CONFIG = r'D:\StoreDaily\Mesh.ini' section_params = ini_worker.get_section_from_ini(INI_CONFIG, 'INFILL') for key, value in section_params.iteritems(): if key == 'cross': if int(value) == 0: print 'INFILL PATTERN SWITCHHED TO CROSS' ini_worker.write_to_section(INI_CONFIG, 'INFILL', 'cross', 1) else: print 'INFILL PATTERN SWITCHHED TO PARALLEL' ini_worker.write_to_section(INI_CONFIG, 'INFILL', 'cross', 0)
def main(): """ gcode2cutsim needs to be compiled to exe :return: Nothing """ G2CLOG = G2CLogging.G2CLogging() # start logger try: # initialize classes WD = '' Tool = Tools.Tools() # initialize Tools ExUtil = ExtrusionUtil.ExtrusionUtil() StrManipulate = StrManipulator.StrManipulator() JobS = JobSetup.JobSetup() evalGcode = evaluateGCode.evaluateGcode() NCFileR = NCFileReader.NCFileReader() # define constant vars SIMPRECISION = 0.2 # default precision of simulation. precision is increased when layer thickness is smaller # TODO define number of layer by a layer interval -> slider SLIDERPOSITION_START = 25 # percentage SLIDERPOSITION_END = 33 # percentage silent_process = False if os.path.exists('C:\MW3DPrinting\Mesh.ini'): sim_params = ini_worker.get_section_from_ini( 'C:\MW3DPrinting\Mesh.ini', 'SIMULATION') else: sim_params = {} sim_params['rot_axis'] = 'False' # get all input parameters from user inputParams = sys.argv if len(inputParams) == 1: import UI.selectFile as fselect userHelp() path, filename = fselect.get_file_list() if filename is None: G2CLOG.wlog('INFO', 'File selection canceled ... Nothing to process') print 'Canceled' return inputf = path + '\\' + str(filename)[3:-2] inputParams += [inputf] inputParams += ['-sim'] elif len(inputParams) >= 2: if len(inputParams) == 2 and inputParams[-1] == '-re': print 'Command ' + inputParams[-1] print 'Recalculating simulation files' tmpIP = inputParams[-1] inputParams.pop() cl_file = 'Mesh.cl' sim_file = 'Mesh.sim' if os.path.isfile(cl_file): os.remove(cl_file) if os.path.isfile(sim_file): os.remove(sim_file) inputParams.append('Mesh.gcode') inputParams.append('Mesh.ini') inputParams.append(tmpIP) if not os.path.isfile(inputParams[1]): print 'No such file -> ' + str(inputParams[1]) return else: inputf = str(inputParams[1]) if len(inputParams) >= 3: if not os.path.isfile(inputParams[2]): print 'No config file -> ' + str(inputParams[1]) return else: CD = configData.configData(inputParams[2]) # get working directory when Mesh.ini was passed via command line splittedStr = inputParams[2].split('\\')[:-1] for item in splittedStr: WD = WD + item + '\\' Tool = Tools.Tools(configData=CD) # initialize Tools # read simulation precision SIMPRECISION = getSimulationPrecision(inputParams[2]) if len(inputParams) == 4: if inputParams[3][1:].strip() == 'silent': silent_process = True print 'Silent parsing' else: inputParams += ['-sim'] else: inputParams += ['-sim'] pointpos = inputf.rfind('.') if pointpos != -1: outputf = inputf[:pointpos + 1] + 'cl' outputfMS = inputf[:pointpos + 1] + 'sim' else: outputf = inputf + 'cl' outputfMS = inputf + 'sim' rushed_through_calculation = False if compare.sim_files(inputf, outputf) or compare.sim_files( inputf, outputfMS): CLWriter = CLFileWriter.CLFileWriter( outputf) # start CL File writer CLMSWriter = CLFileWriter.CLFileWriter(outputfMS) # open and create CL file CLWriter.openCLFile() CLMSWriter.openCLFile() ArcS = arcSuite.arcsuite() # initialize arcsuite DistS = distanceSuite.distanceSuite() # initialize arcsuite # initialize const # ------------------------------------------------------------------------------------------------------------ startParsing = False zValMachine = 0 LayerThickness = 0 currentMachinePos = (0, 0) forerunMachinePos = (0, 0) rotationValue = 0 rotationValueLast = 0 distance = 0 feedRate = 0 # EXTRUSIONLINEOVERLAP = 0 # [mm] ExtrusionLineOverlap = 0 # percent # EXTENDADDITIVEBOX = 1 # [mm] extendAdditiveBox = 1 # [mm] lineLloop = None moveCounter = 0 # ------------------------------------------------------------------------------------------------------------ G2CLOG.wlog('INFO', 'Starting G2C conversion ...') # open NC file reader and get a block of code flNC = open(inputf, 'r') # read only NCBlock, flNC = NCFileR.getNCBlock( flNC, blocklength=15) # get NC block code flNC.close() # get initial layer width. To calculate initial LW we need a few lines of code. # At least 2 consecutive G1 moves with extrusion value. LayerWidthMachine = ExUtil.getInitialLayerWidth(NCBlock) currentExtrusionVal = ExUtil.getInitialExtrusionVal(NCBlock) # write header # stockDimStr = JobS.getStockDimensionStr() homePosStr = JobS.getHomePosStr() # CLWriter.writeNCCode(stockDimStr) CLWriter.writeNCCode('STOCK') CLWriter.writeNCCode( 'ADDITIVEBOX' ) # place holder. We replace this line with calculated part dimensions. # We know them after every line from G-Code is procecssed. # We use this line to find the right line to replace CLWriter.writeNCCode(homePosStr) # write information in MachSim File CLMSWriter.writeNCCode('MW_UNITS_METRIC 1') if not silent_process: app = wx.App(False) pulse_dlg = wx.ProgressDialog(title="G2C Converting ...", message="Initializing ...", maximum=int(101), style=wx.PD_CAN_ABORT | wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME) num_lines = sum(1 for line in open(inputf)) next_update_block = 0 keepGoin = 1 counter_G1 = 0 with open(inputf) as fidO: # start reading g-Code file # ----- loopCounter = 0 for line in fidO: loopCounter += 1 # save line to lineC -> keeps original lineC = line perc = round((loopCounter / float(num_lines) * 100)) if perc > next_update_block: next_update_block += 0.1 if not silent_process: updmessage = 'Line ' + str( loopCounter) + ' of ' + str( num_lines) + ' - ' + str(perc) + '%' (keepGoin, skip) = pulse_dlg.Update(perc, updmessage) if not keepGoin: G2CLOG.wlog( 'INFO', 'User canceled at line: ' + str(loopCounter) + ' - ' + str(perc) + '%') existent = 2 break # check where g-code actually starts and give green light to parsing functions True/False if line[0] == 'G': moveCounter += 1 startParsing = True else: startParsing = False if line[0] == ';': # cancel/go back to loop if line is commented continue pos = line.find('Z') if pos != -1: posShifter = 8 while 1: try: # TODO automatic detection of white space in line string zValForerun = float( line[pos + 1:pos + posShifter]) # get z value break except: posShifter -= 1 LayerThicknessForerun = zValForerun - zValMachine if numpy.isclose( LayerThicknessForerun, LayerThickness, 0.05 ) is False: # check if in tolerance after subtraction # this one is occuring only once geometryStr, midpoint, radius, width = Tool.getGeometry( LayerThickness=LayerThicknessForerun, LayerWidth=LayerWidthMachine, ELOverlap=ExtrusionLineOverlap) CLWriter.writeToolChange(geometryStr) CLMSWriter.writeToolChange(str(width), NC_Style='MachSim') XYpos = 'X' + str( currentMachinePos[0]) + ' Y' + str( currentMachinePos[1]) distance = DistS.get_distance_between_points( currentMachinePos, forerunMachinePos) timeStr = ' TIME' + str(distance / (1000.0 / 60.0)) moveStr = ' MOVE' + str(moveCounter) feedStr = ' F' + str(feedRate) CLMSWriter.writeNCCode('MW_MACHMOVE RAPID ' + XYpos + ' Z' + str(zValMachine) + feedStr + timeStr + moveStr) moveCounter += 1 LayerThickness = LayerThicknessForerun if LayerThickness < SIMPRECISION: SIMPRECISION = LayerThickness zValMachine = zValForerun CLMSWriter.Z_level = zValMachine CLWriter.Z_level = zValMachine CLWriter.layerNr += 1 CLMSWriter.layerNr += 1 CLMSWriter.path_area_index = 0 # get geometry of extrusion lines and layers before proceeding with tool etc. if line[0:2] == 'G1' and line[0:3].find( ' ' ) != -1: # find white space to intercept G commands over and equal 10 counter_G1 += 1 if lineLloop is not None and LayerThicknessForerun != 0: # get current positions and extrusion values forerunMachinePos = ExUtil.getCoordinates(line) if forerunMachinePos is not None: forerunMachinePos = (forerunMachinePos[1], forerunMachinePos[2]) rotationValue = ArcS.arc_from_points( currentMachinePos, forerunMachinePos) rotationValue += 90 rotationValue = ArcS.adapt_full_rotation( rotationValue) ArcS.current_arc = rotationValue ArcS.first_move = False distance = DistS.get_distance_between_points( currentMachinePos, forerunMachinePos) rotationValueLast = rotationValue forerunExtrusionVal = ExUtil.getExtrusionVal(line) LayerWidth = ExUtil.getLayerWidth( currentMachinePos, forerunMachinePos, currentExtrusionVal, forerunExtrusionVal, LayerThicknessForerun) if numpy.isclose( LayerWidthMachine, LayerWidth, 0.05 ) is False: # check if in tolerance after subtraction geometryStr, midpoint, radius, width = Tool.getGeometry( LayerThickness=LayerThicknessForerun, LayerWidth=LayerWidth, ELOverlap=ExtrusionLineOverlap) if geometryStr is not None: if float(geometryStr.split(' ') [2]) >= LayerThickness * 2.4: # LayerThickness = 0.2, LayerWidth = 0.48, ELOverlap = 0.15 G2CLOG.wlog( 'INFO', 'Overextrusion detected: ') G2CLOG.wlog( 'INFO', 'Pos in G-Code ---> ' + str(loopCounter)) G2CLOG.wlog('INFO', geometryStr) CLWriter.writeToolChange(geometryStr) # CLMSWriter.writeToolChange(str(width), NC_Style='MachSim') rotationAxis = 'C0 A' + str( rotationValue) + ' B0' feedStr = ' F' + str(feedRate) timeStr = ' TIME' + str(distance / (1000.0 / 60.0)) moveStr = ' MOVE' + str(moveCounter) if 'rot_axis' not in sim_params: sim_params['rot_axis'] = 'False' if sim_params['rot_axis'] == 'True': CLMSWriter.writeNCCode( 'MW_MACHMOVE FEED ' + 'X' + str(currentMachinePos[0]) + ' Y' + str(currentMachinePos[1]) + ' Z' + str(zValMachine) + ' ' + rotationAxis + feedStr + timeStr + moveStr) else: CLMSWriter.writeNCCode( 'MW_MACHMOVE FEED ' + 'X' + str(currentMachinePos[0]) + ' Y' + str(currentMachinePos[1]) + ' Z' + str(zValMachine) + ' ' + feedStr + timeStr + moveStr) moveCounter += 1 LayerWidthMachine = LayerWidth lineLloop = line currentExtrusionVal = ExUtil.getExtrusionVal(line) else: lineLloop = line if line[0:3] == 'G1 ' or line[0:3] == 'G0 ': # get current machine position from NC line currentMachinePos = ExUtil.getCoordinates(line) if currentMachinePos is not None: currentMachinePos = (currentMachinePos[1], currentMachinePos[2]) # X,Y # write g-code to cutsim format if startParsing == True: line = line.rstrip('\n') # remove next line chars line = StrManipulate.sepStr(line, 'G') line = StrManipulate.sepStr(line, 'E') lineMS = copy.deepcopy(line) lineMS = StrManipulate.vartype(line, 'F', 'int') line = StrManipulate.sepStr(line, 'F') if len(lineMS.split('F')) > 1: feedRate = int(lineMS.split('F')[1]) line = StrManipulate.insertWS(line, 'X') line = StrManipulate.insertWS(line, 'Y') line = StrManipulate.insertWS(line, 'Z') if lineC[0:3] == 'G1 ': if line.find('G') == -1: CLWriter.writeNCCode( 'CUT ' + line + ' TX 0 TY 0 TZ 1 ROLL 0 ;') direction = line direction = lineC rotationAxis = 'C0 A' + str( rotationValue) + ' B0' feedStr = ' F' + str(feedRate) timeStr = ' TIME' + str(distance / (1000.0 / 60.0)) moveStr = ' MOVE' + str(moveCounter) if 'rot_axis' not in sim_params: sim_params['rot_axis'] = 'False' if sim_params['rot_axis'] == 'True': CLMSWriter.writeNCCode( 'MW_MACHMOVE FEED ' + lineMS + rotationAxis + feedStr + timeStr + moveStr) else: CLMSWriter.writeNCCode( 'MW_MACHMOVE FEED ' + lineMS + feedStr + timeStr + moveStr) evalGcode.saveAxValLimits('X', lineC) evalGcode.saveAxValLimits('Y', lineC) elif lineC[0:3] == 'G0 ': # rapid move CLWriter.writeNCCode('MOVE ' + line + ' TX 0 TY 0 TZ 1 ROLL 0 ;') rotationAxis = 'C0 A0 B0' timeStr = ' TIME' + str(distance / (1000.0 / 60.0)) moveStr = ' MOVE' + str(moveCounter) CLMSWriter.writeNCCode('MW_MACHMOVE RAPID ' + lineMS + timeStr + moveStr) # + rotationAxis) evalGcode.saveAxValLimits('Z', lineC) CLWriter.closeNCFile() # close CL writer and close CL file CLMSWriter.writeNCCode('MW_OP_END') CLMSWriter.closeNCFile() AdditiveBoxDim = evalGcode.getSavedAxLimits() ADDITIVEBOX = [ AdditiveBoxDim[0]['X'] - extendAdditiveBox, AdditiveBoxDim[0]['Y'] - extendAdditiveBox, AdditiveBoxDim[0]['Z'] - extendAdditiveBox, AdditiveBoxDim[1]['X'] + extendAdditiveBox, AdditiveBoxDim[1]['Y'] + extendAdditiveBox, AdditiveBoxDim[1]['Z'] + extendAdditiveBox ] JobS.ADDITIVEBOX = ADDITIVEBOX partDimStr = JobS.getABDimensionStr() for line in fileinput.input(outputf, inplace=1): print line.replace("ADDITIVEBOX", partDimStr), # find position of stock model JobS.set_stock_position() for line in fileinput.input(outputf, inplace=1): stockDimStr = JobS.getStockDimensionStr() print line.replace("STOCK", stockDimStr), print 'Done. CL file written - > ' + outputf print 'Done. SIM file written - > ' + outputfMS rushed_through_calculation = True # gcode2cutsimFDM D:\MW3DPrinting_MachSim\Mesh.gcode D:\MW3DPrinting_MachSim\Mesh.ini -MachSim if len(inputParams) >= 3: if inputParams[-1] == '-sim': print 'Starting verification' # writing configuration (start options) file for verifier # TODO create own def to write ini file # CLUtilities.INIFileWriter() posDir = outputf.rfind('\\') posPoint = outputf[posDir + 1:].rfind('.') iniFileName = outputf[posDir + 1:posDir + 1 + posPoint] iniFileName = iniFileName + '_SIMULATION.ini' iniDirName = outputf[0:posDir + 1] NCiniFile = iniDirName + iniFileName if rushed_through_calculation: fh = open(NCiniFile, 'w') fh.write('nc=' + outputf[posDir + 1:] + '\n') fh.write('precision=' + str(SIMPRECISION) + '\n') fh.write('model=3\n') fh.close() if inputParams[-2] == '-MachSim' or inputParams[ -2] == '-Verifier': startVerification(outputf, NCiniFile, WD, simType=inputParams[-2][1:]) else: startVerification(outputf, NCiniFile, WD) G2CLOG.wlog('INFO', 'All jobs done ...') except Exception as e: raise message = traceback.format_exc().splitlines( ) # get last error and prepare to write it in logger for i in message: G2CLOG.wlog('ERROR', str(i))
def compare_parameters(self): """ :return: """ print bcolors.BOLD + '\nMATCHING SECTION PARAMETER' + bcolors.END for section in self.section_list_orig: self.section_param_orig[section] = ini_worker.get_section_from_ini( self.config_orig, section) for section in self.section_list_test: self.section_param_test[section] = ini_worker.get_section_from_ini( self.config_test, section) intersection_list = list( set(self.section_list_orig).intersection(self.section_list_test)) differ_list_orig = list( set(self.section_list_orig).difference(self.section_list_test)) differ_list_test = list( set(self.section_list_test).difference(self.section_list_orig)) # proof -> seen from original MASTER document if len(differ_list_orig) != 0: print bcolors.RED + str( differ_list_orig) + ' -> MISSING' + bcolors.END # proof -> seen from WANT TO COMMIT document if len(differ_list_test) != 0: print bcolors.LIGHTRED + str( differ_list_test) + ' -> COMMIT REQUEST' + bcolors.END # proof parameters of sections section_differ = [] for key in intersection_list: print bcolors.BOLD + 'CHECKING: ' + key + bcolors.END # from MASTER side differ_params_orig = list( set(self.section_param_orig[key]).difference( self.section_param_test[key])) # from TESTER side differ_params_test = list( set(self.section_param_test[key]).difference( self.section_param_orig[key])) if len(differ_params_orig) == 0 and len(differ_params_test) == 0: print bcolors.GREEN + key + ' -> MATCH' + bcolors.END else: if len(differ_params_orig) != 0: section_differ.append(key) differ_param_list = list( set(self.section_param_orig[key]).difference( self.section_param_test[key])) print bcolors.RED + key + ' -> MISSING -> ' + str( differ_param_list) + bcolors.END if len(differ_params_test) != 0: section_differ.append(key) differ_param_list = list( set(self.section_param_test[key]).difference( self.section_param_orig[key])) print bcolors.LIGHTRED + key + ' -> REQUEST -> ' + str( differ_param_list) + bcolors.END
def __init__(self, pluginPath, corePath, configFile): self.pluginPath = pluginPath self.corePath = corePath self.workingDir = sys.path[0] self.configFile = self.corePath + '\\' + configFile self.PGconfigFile = self.workingDir + '\\' + 'PG_config.ini' self.PGconfigFileCore = self.corePath + '\\' + 'PG_config.ini' self.PG_expanded = False self.current_y_pxpos_elem = 0 self.param_dict = {} self.section_EC_stat = {} self.KST = key_stroke_timer.key_stroke_timer(self.configFile) self.MIN_SIZE_W = 20 self.black_list = ['collapse', 'create', 'hideSection', 'show', 'filterStrategy', 'offsetType'] self.GOC = guard.guard_of_changes(self) # init observer thread self.GOC.start() # start observer thread wx.Dialog.__init__(self, None, title='MW Parameter guard', size=UI.WMAIN['size'], style=wx.SYSTEM_MENU | # wx.CAPTION | # ~wx.CLOSE_BOX | wx.TAB_TRAVERSAL | wx.STAY_ON_TOP | wx.RESIZE_BORDER) # | wx.TRANSPARENT_WINDOW) self.SetMinSize((1, 1)) PG_XY = ini_worker.get_param_from_ini(self.PGconfigFileCore, 'UISETTINGS', 'lastWindowPosition') PG_XY = PG_XY.strip()[1:-1].split(',') PG_SIZE = ini_worker.get_param_from_ini(self.PGconfigFileCore, 'UISETTINGS', 'lastWindowSize') PG_SIZE = PG_SIZE.strip()[1:-1].split(',') self.MAIN_DISPLAY_SIZE = get_monitors() if len(self.MAIN_DISPLAY_SIZE) == 1: self.DISPLAY_SIZE = self.MAIN_DISPLAY_SIZE[0] else: self.DISPLAY_SIZE = self.MAIN_DISPLAY_SIZE[1] self.DISPLAY_SIZE = self.MAIN_DISPLAY_SIZE[0] #self.MoveXY(int(PG_XY[0]), int(PG_XY[1])) self.MoveXY(int(self.DISPLAY_SIZE.width)-10, 0) #self.SetSizeWH(int(PG_SIZE[0]), int(PG_SIZE[1])) self.SetSizeWH(int(PG_SIZE[0]), self.DISPLAY_SIZE.height) self.Bind(wx.EVT_SIZE, self.OnSize, self) # self.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver) # self.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave) # self.Bind(wx.EVT_LEFT_DOWN, self.onLMouseDown) self.Bind(wx.EVT_MOUSE_EVENTS, self.onMouseEvents) atable = wx.AcceleratorTable([(wx.ACCEL_NORMAL, wx.WXK_ESCAPE, wx.ID_EXIT)]) self.SetAcceleratorTable(atable) wx.EVT_MENU(self, wx.ID_EXIT, self.OnExit) self.SetBackgroundColour(wx.Colour(UI.WCOLOR['BG'][0], UI.WCOLOR['BG'][1], UI.WCOLOR['BG'][2])) self.SetTransparent(220) self.Show() #fn = self.corePath + '\\bin\\images\\paramGuard.ico' #self.icon = wx.Icon(fn, wx.BITMAP_TYPE_ICO) #self.SetIcon(self.icon) self.section_list = ini_worker.get_sections_list_from_ini(self.configFile) # list param_indentation = 10 # whitespace for section in self.section_list: self.section_EC_stat.update( {section: ini_worker.get_param_from_ini(self.configFile, section, 'collapse')}) section_params = ini_worker.get_section_from_ini(self.configFile, section) for param, value in section_params.iteritems(): if param == 'hideSection': hideSection = value if not hideSection: self.param_dict[section] = {} font = wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.BOLD) headline = wx.StaticText(self, label=section, pos=(UI.THEADERSTART['pos'][0], UI.THEADERSTART['pos'][1] + self.current_y_pxpos_elem)) headline.SetForegroundColour(UI.TCOLOR['FG']) # set text color headline.SetFont(font) headline.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver) #headline.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave) button = wx.Button(self, name=section, label="", pos=(UI.BEXPAND['pos'][0], self.current_y_pxpos_elem + 11), size=UI.BEXPAND['size']) button.Bind(wx.EVT_BUTTON, self.expandCollapse) button.SetBackgroundColour(UI.BCOLOR['BG']) # set color button.SetToolTipString('Click to expand/collapse section') button.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver) #button.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave) self.current_y_pxpos_elem += 20 # params in sections (edit boxes) font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL) ui_elem_handler_dict = {} for param, value in section_params.iteritems(): if type(value) == str: splitted_value = value.split(';') if len(splitted_value) > 1: if splitted_value[1].strip() == 'X': self.black_list.append(param) if param not in self.black_list: text = wx.StaticText(self, label=param, pos=(UI.THEADERSTART['pos'][0] + param_indentation, UI.THEADERSTART['pos'][1] + self.current_y_pxpos_elem)) text.SetForegroundColour(UI.PARAMCOLOR['FG']) # set text color text.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver) #text.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave) editbox = (wx.TextCtrl(self, name=section + ' - ' + param, value=str(value), pos=(UI.EBOX['pos'][0], UI.THEADERSTART['pos'][1] + self.current_y_pxpos_elem), size=UI.EBOX['size'], style=wx.TE_PROCESS_ENTER)) editbox.SetForegroundColour(UI.ECOLOR2['FG']) # set color editbox.SetBackgroundColour(UI.ECOLOR2['BG']) # set color editbox.Bind(wx.EVT_TEXT, self.EvtText) editbox.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver) #editbox.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave) elem_dict = {param: [{'ebox': [editbox, value]}, {'headline': headline}, {'text': text}, {'button': button}]} ui_elem_handler_dict.update(elem_dict) self.current_y_pxpos_elem += 20 self.param_dict[section].update(ui_elem_handler_dict) self.expandCollapse(None, refresh=True) self.refresh_UI() self.KST.start()
def __init__(self, pluginPath, corePath, configFile): self.pluginPath = pluginPath self.corePath = corePath self.workingDir = sys.path[0] self.configFile = self.corePath + '\\' + configFile self.PGconfigFile = self.workingDir + '\\' + 'PG_config.ini' self.PGconfigFileCore = self.corePath + '\\' + 'PG_config.ini' self.PG_expanded = False self.current_y_pxpos_elem = 0 self.param_dict = {} self.section_EC_stat = {} self.KST = key_stroke_timer.key_stroke_timer(self.configFile) self.MIN_SIZE_W = 20 self.black_list = [ 'collapse', 'create', 'hideSection', 'show', 'filterStrategy', 'offsetType' ] self.GOC = guard.guard_of_changes(self) # init observer thread self.GOC.start() # start observer thread wx.Dialog.__init__( self, None, title='MW Parameter guard', size=UI.WMAIN['size'], style=wx.SYSTEM_MENU | # wx.CAPTION | # ~wx.CLOSE_BOX | wx.TAB_TRAVERSAL | wx.STAY_ON_TOP | wx.RESIZE_BORDER) # | wx.TRANSPARENT_WINDOW) self.SetMinSize((1, 1)) PG_XY = ini_worker.get_param_from_ini(self.PGconfigFileCore, 'UISETTINGS', 'lastWindowPosition') PG_XY = PG_XY.strip()[1:-1].split(',') PG_SIZE = ini_worker.get_param_from_ini(self.PGconfigFileCore, 'UISETTINGS', 'lastWindowSize') PG_SIZE = PG_SIZE.strip()[1:-1].split(',') self.MAIN_DISPLAY_SIZE = get_monitors() if len(self.MAIN_DISPLAY_SIZE) == 1: self.DISPLAY_SIZE = self.MAIN_DISPLAY_SIZE[0] else: self.DISPLAY_SIZE = self.MAIN_DISPLAY_SIZE[1] self.DISPLAY_SIZE = self.MAIN_DISPLAY_SIZE[0] #self.MoveXY(int(PG_XY[0]), int(PG_XY[1])) self.MoveXY(int(self.DISPLAY_SIZE.width) - 10, 0) #self.SetSizeWH(int(PG_SIZE[0]), int(PG_SIZE[1])) self.SetSizeWH(int(PG_SIZE[0]), self.DISPLAY_SIZE.height) self.Bind(wx.EVT_SIZE, self.OnSize, self) # self.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver) # self.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave) # self.Bind(wx.EVT_LEFT_DOWN, self.onLMouseDown) self.Bind(wx.EVT_MOUSE_EVENTS, self.onMouseEvents) atable = wx.AcceleratorTable([(wx.ACCEL_NORMAL, wx.WXK_ESCAPE, wx.ID_EXIT)]) self.SetAcceleratorTable(atable) wx.EVT_MENU(self, wx.ID_EXIT, self.OnExit) self.SetBackgroundColour( wx.Colour(UI.WCOLOR['BG'][0], UI.WCOLOR['BG'][1], UI.WCOLOR['BG'][2])) self.SetTransparent(220) self.Show() #fn = self.corePath + '\\bin\\images\\paramGuard.ico' #self.icon = wx.Icon(fn, wx.BITMAP_TYPE_ICO) #self.SetIcon(self.icon) self.section_list = ini_worker.get_sections_list_from_ini( self.configFile) # list param_indentation = 10 # whitespace for section in self.section_list: self.section_EC_stat.update({ section: ini_worker.get_param_from_ini(self.configFile, section, 'collapse') }) section_params = ini_worker.get_section_from_ini( self.configFile, section) for param, value in section_params.iteritems(): if param == 'hideSection': hideSection = value if not hideSection: self.param_dict[section] = {} font = wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.BOLD) headline = wx.StaticText(self, label=section, pos=(UI.THEADERSTART['pos'][0], UI.THEADERSTART['pos'][1] + self.current_y_pxpos_elem)) headline.SetForegroundColour(UI.TCOLOR['FG']) # set text color headline.SetFont(font) headline.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver) #headline.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave) button = wx.Button(self, name=section, label="", pos=(UI.BEXPAND['pos'][0], self.current_y_pxpos_elem + 11), size=UI.BEXPAND['size']) button.Bind(wx.EVT_BUTTON, self.expandCollapse) button.SetBackgroundColour(UI.BCOLOR['BG']) # set color button.SetToolTipString('Click to expand/collapse section') button.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver) #button.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave) self.current_y_pxpos_elem += 20 # params in sections (edit boxes) font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL) ui_elem_handler_dict = {} for param, value in section_params.iteritems(): if type(value) == str: splitted_value = value.split(';') if len(splitted_value) > 1: if splitted_value[1].strip() == 'X': self.black_list.append(param) if param not in self.black_list: text = wx.StaticText( self, label=param, pos=(UI.THEADERSTART['pos'][0] + param_indentation, UI.THEADERSTART['pos'][1] + self.current_y_pxpos_elem)) text.SetForegroundColour( UI.PARAMCOLOR['FG']) # set text color text.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver) #text.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave) editbox = (wx.TextCtrl(self, name=section + ' - ' + param, value=str(value), pos=(UI.EBOX['pos'][0], UI.THEADERSTART['pos'][1] + self.current_y_pxpos_elem), size=UI.EBOX['size'], style=wx.TE_PROCESS_ENTER)) editbox.SetForegroundColour( UI.ECOLOR2['FG']) # set color editbox.SetBackgroundColour( UI.ECOLOR2['BG']) # set color editbox.Bind(wx.EVT_TEXT, self.EvtText) editbox.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver) #editbox.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave) elem_dict = { param: [{ 'ebox': [editbox, value] }, { 'headline': headline }, { 'text': text }, { 'button': button }] } ui_elem_handler_dict.update(elem_dict) self.current_y_pxpos_elem += 20 self.param_dict[section].update(ui_elem_handler_dict) self.expandCollapse(None, refresh=True) self.refresh_UI() self.KST.start()