⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 view238.java

📁 The view238 application is a simple tool for graphically displaying STEP-NC toolpaths. It is a Java
💻 JAVA
字号:
/* $RCSfile: coolant.cxx,v $
 * $Revision: 1.3 $ $Date: 2006/08/21 14:15:51 $
 * 
 * Copyright (c) 1991-2006 by STEP Tools Inc. 
 * All Rights Reserved.
 * 
 * This file may be distributed and/or modified under the terms of 
 * the GNU General Public License version 2 as published by the Free
 * Software Foundation and appearing in the file LICENSE.GPL included
 * with this file.
 * 
 * THIS FILE IS PROVIDED "AS IS" WITH NO WARRANTY OF ANY KIND,
 * INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE.
 * 
 * 		----------------------------------------
 */

package com.steptools.view238;

import java.io.*;
import java.awt.BorderLayout;
import java.awt.event.*;
import javax.swing.*;        
import javax.swing.event.*;

class ListContents extends AbstractListModel {
    final StepNcModel model;
    
    ListContents(StepNcModel mod) {
	model = mod;
    }
    
    public Object getElementAt(int index) {
	StepNcModel.ToolPath tp = model.toolpaths.get(index);
	return tp.getName();
    }

    public int getSize() {
	return  model.toolpaths.size();
    }
}

/**
 * GUI interface to display toolpaths in a AP238 file.
 */
public class View238 {

    static final String VERSION = "1.0";
    
    /**
     * Load the toolpath data into he 3d viewer
     */
    private static void loadViewer(ThreeD viewer, ListSelectionModel lm,
				   StepNcModel mod) {
    }

    private JList list;
    private ThreeD viewer;
    private JFrame frame;
    
    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private void createAndShowGUI() {

	try {
	    UIManager.setLookAndFeel(
		UIManager.getSystemLookAndFeelClassName());
	} catch (Exception ex) {}
	
        //Create and set up the window.
        frame = new JFrame("AP238 Toolpath Viewer");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	viewer = new ThreeD();
	frame.getContentPane().add(viewer, BorderLayout.CENTER);	

	list = new JList();
	list.setPrototypeCellValue("123456789012345678901234567");
	list.addListSelectionListener(new ListSelectionListener() {
	    public void valueChanged (ListSelectionEvent lse) {
		int first = lse.getFirstIndex();
		int last = lse.getLastIndex();
		boolean is_adj = lse.getValueIsAdjusting();
		if (is_adj)
		    return;
		
		viewer.forceRepaint();
	    }
	});
	JScrollPane scroll = new JScrollPane(list);
	scroll.setHorizontalScrollBarPolicy
	    (ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
	frame.getContentPane().add(scroll, BorderLayout.LINE_START);

	JPanel bottom = new JPanel();
	frame.getContentPane().add(bottom, BorderLayout.PAGE_END);

	JButton select = new JButton("Select All");
	bottom.add(select);
	select.addActionListener(new ActionListener() {
	    public void actionPerformed (ActionEvent ev) {
		selectAll();
	    }
	});

	JButton clear = new JButton("Clear All");
	bottom.add(clear);
	clear.addActionListener(new ActionListener() {
	    public void actionPerformed (ActionEvent ev) {
		list.clearSelection();
	    }
	});
	
	final JFileChooser fc = new JFileChooser();
	JButton open = new JButton("Load File...");
	bottom.add(open);
	open.addActionListener(new ActionListener() {
	    public void actionPerformed (ActionEvent ev) {
		int ret = fc.showOpenDialog(frame);
		if (ret == JFileChooser.APPROVE_OPTION) {
		    File file = fc.getSelectedFile();
		    loadModel(file);
		}
	    }
	});

	JButton about = new JButton("About...");
	bottom.add(about);
	about.addActionListener(new ActionListener() {
	    public void actionPerformed (ActionEvent ev) {
	    JOptionPane.showMessageDialog
		(frame,
		 "View238 AP238 Toolpath Viewer.  Version "+VERSION+"\n"+
		 "Copyright \251 2006 STEP Tools, Inc.\n\n"+
                 "This is free software.  You may redistribute copies of it\n"+
		 "under the terms of the GNU General Public License\n"+
		 "<http://www.gnu.org/licenses/gpl.html>.\n\n" +
		 "There is NO WARRANTY, to the extent permitted by law.\n\n" +
		 "Source code is available at <http://www.steptools.com/>",
		 "About View238", JOptionPane.INFORMATION_MESSAGE);
	    }
	});	

	
	JButton exit = new JButton("Exit");
	bottom.add(exit);
	exit.addActionListener(new ActionListener() {
	    public void actionPerformed (ActionEvent ev) {
		frame.dispose();
	    }
	});	
	
        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    private void selectAll() {
	int sz = list.getModel().getSize();
	list.setSelectionInterval(0, sz-1);
    }

    
    private void loadModel(File file)  {

	try {
	    StepNcModel mod = new StepNcModel(file);
	    list.setModel(new ListContents(mod));
	
	    Model3D md = new Model3D(list.getSelectionModel());
	    int count =0;

	    int sz = mod.toolpaths.size();
	    for (int i=0; i<sz; i++) {
		StepNcModel.ToolPath tp = mod.toolpaths.get(i); 
		
		for (StepNcModel.Curve c : tp.curves) {
		    if (c instanceof StepNcModel.LineSegment) {
			StepNcModel.LineSegment s = (StepNcModel.LineSegment)c;
			md.addVert(s.x1, s.y1, s.z1);
			md.addVert(s.x2, s.y2, s.z2);
			md.add(count, count+1, i);
			count+=2;
		    }
		    
		    else if (c instanceof StepNcModel.Arc) {
			StepNcModel.Arc a = (StepNcModel.Arc) c;
			
			/* This simply draws a line between the trim points.
			   We should do a better job of faceting the circle
			*/
			
			md.addVert(a.tx1, a.ty1, a.tz1);
			md.addVert(a.tx2, a.ty2, a.tz2);
			md.add(count, count+1, i);
			count+=2;
		    }
		    
		    else
			throw new RuntimeException ("Unexpected case");
		}
	    }
	    
	    viewer.setModel(md);
	    selectAll();
	} catch (Exception ex) {
	    JOptionPane.showMessageDialog
		(frame,	 "Got exception: " +ex.getMessage());
	}
    }

    public static void main(String[] argv)
	throws IOException, StepNcException {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.

	File data = null;
	if (argv.length > 0)
	    data = new File(argv[0]);
	
	final File file = data;

	final View238 view238 = new View238();
	
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
		try {
		    view238.createAndShowGUI();
		    if (file != null)
			view238.loadModel(file);
		} catch (Exception ex) {
		    throw new RuntimeException(ex); 
		}
            }
        });
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -