private static GeoElement updateOldValue( Kernel kernel, GeoElement oldValue, String name, String text) throws Exception { String text0 = text; if (text.charAt(0) == '=') { text = text.substring(1); } GeoElement newValue = null; try { // always redefine objects in spreadsheet, don't store undo info // here newValue = kernel .getAlgebraProcessor() .changeGeoElementNoExceptionHandling(oldValue, text, true, false); // newValue.setConstructionDefaults(); newValue.setAllVisualProperties(oldValue, true); if (oldValue.isAuxiliaryObject()) { newValue.setAuxiliaryObject(true); } // Application.debug("GeoClassType = " + // newValue.getGeoClassType()+" " + newValue.getGeoClassType()); if (newValue.getGeoClassType() == oldValue.getGeoClassType()) { // newValue.setVisualStyle(oldValue); } else { kernel.getApplication().refreshViews(); } } catch (CircularDefinitionException cde) { kernel.getApplication().showError("CircularDefinition"); return null; } catch (Throwable e) { // if exception is thrown treat the input as text and try to update // the cell as a GeoText { // reset the text string if old value is GeoText if (oldValue.isGeoText()) { ((GeoText) oldValue).setTextString(text0); oldValue.updateCascade(); } // if not currently a GeoText and no children, redefine the cell // as new GeoText else if (!oldValue.hasChildren()) { oldValue.remove(); // add input as text try { newValue = prepareNewValue(kernel, name, "\"" + text0 + "\""); } catch (Throwable t) { newValue = prepareNewValue(kernel, name, ""); } newValue.setEuclidianVisible(false); newValue.update(); } // otherwise throw an exception and let the cell revert to the // old value else { throw new Exception(e); } } } return newValue; }
/** * @param geo the geo * @return the GeoClass of the wrapped Geo */ public static GeoClass getGeoClassType(GeoElement geo) { return geo.getGeoClassType(); }