use of org.twak.tweed.gen.Gen in project chordatlas by twak.
the class FacadeTool method facadeSelected.
public void facadeSelected(LoopL<Point3d> list, BlockGen block) {
// if (block == null) {
// JOptionPane.showMessageDialog( null, "generate mesh for block first" );
// return;
// }
// Polygonz.findBounds( polies, min, max );
double[] minMax = Loopz.minMax(list);
Loopz.expand(minMax, 30);
Map<Point2d, Pano> panos = new HashMap<>();
for (Gen gen : tweed.frame.gens(PanoGen.class)) for (Pano pg : ((PanoGen) gen).getPanos()) {
Point2d pt = new Point2d(pg.location.x, pg.location.z);
if (pt.x > minMax[0] && pt.x < minMax[1] && pt.y > minMax[4] && pt.y < minMax[5])
panos.put(pt, pg);
}
List<Point3d> objPoints = null;
if (block != null) {
objPoints = new ObjRead(block.getCroppedFile()).points();
}
FacadeFinder ff = new FacadeFinder(Loopz.toXZLoop(list), panos, objPoints, block, tweed.frame.getGenOf(PlanesGen.class));
Point2d cen = Loopz.average(Loopz.to2dLoop(list, 1, null));
renderFacades(block == null ? null : block.gNode, cen.x + "_" + cen.y, ff);
}
use of org.twak.tweed.gen.Gen in project chordatlas by twak.
the class PlaneTool method activate.
@Override
public void activate(Tweed tweed) {
this.tweed = tweed;
List<Gen> gens = tweed.frame.gens(PlanesGen.class);
if (gens.isEmpty()) {
pg = new PlanesGen(tweed);
tweed.frame.addGen(pg, true);
} else
pg = (PlanesGen) gens.get(0);
// createPlane();
}
use of org.twak.tweed.gen.Gen in project chordatlas by twak.
the class TweedFrame method setGens.
public void setGens(List<Gen> nGens) {
for (Gen g : new ArrayList<Gen>(genList)) removeGen(g);
layerList.removeAll();
genList.clear();
for (Gen g : nGens) {
g.gNode = new Node();
g.tweed = tweed;
}
for (Gen g : nGens) {
g.onLoad(tweed);
addGen(g, g.visible);
}
}
use of org.twak.tweed.gen.Gen in project chordatlas by twak.
the class TweedFrame method removeBelowGen.
public void removeBelowGen(Gen below) {
boolean seen = false;
List<Gen> togo = new ArrayList<>();
for (Gen g : genList) {
if (g == below)
seen = true;
if (seen)
togo.add(g);
}
for (Gen g : togo) removeGen(g);
}
use of org.twak.tweed.gen.Gen in project chordatlas by twak.
the class TweedFrame method buildUI.
public JComponent buildUI() {
JPanel out = new JPanel(new BorderLayout());
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
// Build the first menu.
JMenu menu = new JMenu("File");
menuBar.add(menu);
JMenuItem save = new JMenuItem("save", KeyEvent.VK_S);
save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
menu.add(save);
save.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (TweedSettings.folder == null) {
new SimpleFileChooser(frame) {
@Override
public void heresTheFile(File f) throws Throwable {
TweedSettings.folder = f;
TweedSettings.save(false);
}
};
} else
TweedSettings.save(false);
}
});
JMenuItem load = new JMenuItem("open...", KeyEvent.VK_O);
load.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
menu.add(load);
load.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new SimpleFileChooser(frame, false, "select a tweed.xml", Tweed.DATA == null ? null : new File(Tweed.DATA), TWEED_XML) {
@Override
public void heresTheFile(File f) throws Throwable {
TweedSettings.load(f);
}
};
}
});
JMenuItem recent = new JLazyMenu("open recent") {
@Override
public List<Runnable> getEntries() {
List<Runnable> out = new ArrayList();
for (File r : TweedSettings.recentFiles.f) {
out.add(new Runnable() {
@Override
public void run() {
if (!r.exists())
JOptionPane.showMessageDialog(frame, "Location " + r.getName() + "not found (is it still there?)");
else
TweedSettings.load(r);
}
@Override
public String toString() {
return r.getName();
}
});
}
return out;
}
};
menu.add(recent);
JMenuItem neu = new JMenuItem("new...", KeyEvent.VK_N);
neu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
menu.add(neu);
neu.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new SimpleFileChooser(frame, false, "select a file in the root of the workspace") {
@Override
public void heresTheFile(File f) throws Throwable {
TweedSettings.folder = f.getParentFile();
if (new File(TweedSettings.folder, TWEED_XML).exists()) {
JOptionPane.showMessageDialog(frame, TWEED_XML + " already exists at this location, pick another (or delete...)");
return;
}
TweedSettings.load(TweedSettings.folder);
}
};
}
});
// JMenuItem remove = new JMenuItem( "delete layer", KeyEvent.VK_MINUS );
// remove.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_MINUS, ActionEvent.CTRL_MASK ) );
// menu.add( remove );
// remove.addActionListener( new java.awt.event.ActionListener() {
// @Override
// public void actionPerformed( ActionEvent e ) {
// if ( selectedGen != null )
// removeGen( selectedGen );
// };
// } );
JMenuItem resetCam = new JMenuItem("reset view", KeyEvent.VK_R);
resetCam.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK));
menu.add(resetCam);
resetCam.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tweed.resetCamera();
}
});
JMenuItem settings = new JMenuItem("settings...", KeyEvent.VK_R);
settings.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
menu.add(settings);
settings.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new Auto(TweedSettings.settings).frame();
}
});
JMenuItem resetBG = new JMenuItem("reset background", KeyEvent.VK_MINUS);
resetBG.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, ActionEvent.CTRL_MASK));
menu.add(resetBG);
resetBG.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
tweed.enqueue(new Runnable() {
@Override
public void run() {
TweedFrame.this.tweed.clearBackground();
}
});
}
});
JMenuItem obj = new JMenuItem("export obj...", KeyEvent.VK_E);
obj.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
menu.add(obj);
obj.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ObjDump dump = new ObjDump();
for (Gen g : genList) if (g.visible && g instanceof IDumpObjs)
((IDumpObjs) g).dumpObj(dump);
new SimpleFileChooser(frame, true, "save all as obj", new File(Tweed.SCRATCH, "all.obj"), "obj") {
@Override
public void heresTheFile(File f) throws Throwable {
dump.dump(f);
}
};
}
});
layerList = new JPanel(new ListDownLayout());
JPanel layers = new JPanel();
layers.setLayout(new BorderLayout());
layers.add(new JLabel("layers:"), BorderLayout.NORTH);
JScrollPane listScroll = new JScrollPane(layerList);
listScroll.getVerticalScrollBar().setUnitIncrement(50);
listScroll.setPreferredSize(new Dimension(200, 300));
layers.add(listScroll, BorderLayout.CENTER);
JPanel addRemoveLayer = new JPanel();
{
addRemoveLayer.setLayout(new GridLayout(1, 2));
layers.add(addRemoveLayer, BorderLayout.SOUTH);
JButton addLayer = new JButton("+");
addLayer.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
addLayer(e);
}
});
JButton removeLayer = new JButton("-");
removeLayer.addActionListener(e -> removeGen(selectedGen));
addRemoveLayer.add(addLayer);
addRemoveLayer.add(removeLayer);
}
JPanel options = new JPanel(new BorderLayout());
{
options.add(new JLabel("options:"), BorderLayout.NORTH);
options.add(genUI, BorderLayout.CENTER);
}
JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, layers, options);
out.add(pane, BorderLayout.CENTER);
JPanel toolPanel = new JPanel(new ListRightLayout());
tweed.addUI(toolPanel);
coordLabel = new JLabel("");
coordLabel.setHorizontalAlignment(SwingConstants.CENTER);
worldLabel = new JLabel("");
worldLabel.setHorizontalAlignment(SwingConstants.CENTER);
crsLabel = new JLabel("none");
crsLabel.setHorizontalAlignment(SwingConstants.CENTER);
out.add(toolPanel, BorderLayout.NORTH);
JPanel coords = new JPanel(new ListDownLayout());
coords.add(worldLabel);
coords.add(coordLabel);
coords.add(crsLabel);
out.add(coords, BorderLayout.SOUTH);
out.setPreferredSize(new Dimension(300, frame.getHeight()));
return out;
}
Aggregations