Search in sources :

Example 6 with CSGTranslation

use of cbit.vcell.geometry.CSGTranslation in project vcell by virtualcell.

the class CSGObjectTreeCellRenderer method getCSGNodeLabel.

static CSGNodeLabel getCSGNodeLabel(Object object, CSGNodeLabel csgNodeLabel) {
    if (object instanceof CSGObject) {
        CSGObject csgObject = (CSGObject) object;
        csgNodeLabel.text = csgObject.getName();
        java.awt.Color handleColor = new java.awt.Color(getColorMap()[csgObject.getHandle()]);
        csgNodeLabel.icon = new ColorIcon(15, 15, handleColor);
    } else if (object instanceof CSGNode) {
        CSGNode csgNode = (CSGNode) object;
        csgNodeLabel.text = csgNode.getName();
        if (csgNode instanceof CSGPrimitive) {
            CSGPrimitive csgPrimitive = (CSGPrimitive) csgNode;
            switch(csgPrimitive.getType()) {
                case CONE:
                    csgNodeLabel.icon = VCellIcons.csgConeIcon;
                    break;
                case CUBE:
                    csgNodeLabel.icon = VCellIcons.csgCubeIcon;
                    break;
                case CYLINDER:
                    csgNodeLabel.icon = VCellIcons.csgCylinderIcon;
                    break;
                case SPHERE:
                    csgNodeLabel.icon = VCellIcons.csgSphereIcon;
                    break;
            }
            return csgNodeLabel;
        }
        if (csgNode instanceof CSGSetOperator) {
            CSGSetOperator csgSetOperator = (CSGSetOperator) csgNode;
            switch(csgSetOperator.getOpType()) {
                case DIFFERENCE:
                    csgNodeLabel.icon = VCellIcons.csgSetDifferenceIcon;
                    break;
                case INTERSECTION:
                    csgNodeLabel.icon = VCellIcons.csgSetIntersectionIcon;
                    break;
                case UNION:
                    csgNodeLabel.icon = VCellIcons.csgSetUnionIcon;
                    break;
            }
        }
        if (csgNode instanceof CSGTransformation) {
            if (csgNode instanceof CSGRotation) {
                CSGRotation csgRotation = (CSGRotation) csgNode;
                Vect3d axis = csgRotation.getAxis();
                double radius = csgRotation.getRotationRadians();
                csgNodeLabel.text += ", radian=" + radius + ", axis=" + CSGObjectPropertiesPanel.getVect3dDescription(axis);
                csgNodeLabel.icon = VCellIcons.csgRotationIcon;
            } else if (csgNode instanceof CSGTranslation) {
                CSGTranslation csgTranslation = (CSGTranslation) csgNode;
                Vect3d translation = csgTranslation.getTranslation();
                csgNodeLabel.text += ", Translation=" + CSGObjectPropertiesPanel.getVect3dDescription(translation);
                csgNodeLabel.icon = VCellIcons.csgTranslationIcon;
            } else if (csgNode instanceof CSGScale) {
                CSGScale csgScale = (CSGScale) csgNode;
                Vect3d scale = csgScale.getScale();
                csgNodeLabel.text += ", Scale=" + CSGObjectPropertiesPanel.getVect3dDescription(scale);
                csgNodeLabel.icon = VCellIcons.csgScaleIcon;
            } else if (csgNode instanceof CSGHomogeneousTransformation) {
                csgNodeLabel.icon = null;
            }
        }
    }
    return null;
}
Also used : ColorIcon(org.vcell.util.gui.ColorIcon) CSGTranslation(cbit.vcell.geometry.CSGTranslation) CSGTransformation(cbit.vcell.geometry.CSGTransformation) CSGPrimitive(cbit.vcell.geometry.CSGPrimitive) CSGNode(cbit.vcell.geometry.CSGNode) CSGRotation(cbit.vcell.geometry.CSGRotation) Vect3d(cbit.vcell.render.Vect3d) CSGScale(cbit.vcell.geometry.CSGScale) CSGHomogeneousTransformation(cbit.vcell.geometry.CSGHomogeneousTransformation) CSGObject(cbit.vcell.geometry.CSGObject) CSGSetOperator(cbit.vcell.geometry.CSGSetOperator)

Example 7 with CSGTranslation

use of cbit.vcell.geometry.CSGTranslation in project vcell by virtualcell.

the class ClientRequestManager method createNewDocument.

/**
 * Insert the method's description here.
 * Creation date: (5/10/2004 3:48:16 PM)
 */
public AsynchClientTask[] createNewDocument(final TopLevelWindowManager requester, final VCDocument.DocumentCreationInfo documentCreationInfo) {
    // throws UserCancelException, Exception {
    /* asynchronous and not blocking any window */
    AsynchClientTask[] taskArray = null;
    final int createOption = documentCreationInfo.getOption();
    switch(documentCreationInfo.getDocumentType()) {
        case BIOMODEL_DOC:
            {
                AsynchClientTask task1 = new AsynchClientTask("creating biomodel", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

                    @Override
                    public void run(Hashtable<String, Object> hashTable) throws Exception {
                        BioModel bioModel = createDefaultBioModelDocument(null);
                        hashTable.put("doc", bioModel);
                    }
                };
                taskArray = new AsynchClientTask[] { task1 };
                break;
            }
        case MATHMODEL_DOC:
            {
                if ((createOption == VCDocument.MATH_OPTION_NONSPATIAL) || (createOption == VCDocument.MATH_OPTION_SPATIAL_EXISTS)) {
                    AsynchClientTask task2 = new AsynchClientTask("creating mathmodel", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

                        @Override
                        public void run(Hashtable<String, Object> hashTable) throws Exception {
                            Geometry geometry = null;
                            if (createOption == VCDocument.MATH_OPTION_NONSPATIAL) {
                                geometry = new Geometry("Untitled", 0);
                            } else {
                                geometry = (Geometry) hashTable.get(GEOMETRY_KEY);
                            }
                            MathModel mathModel = createMathModel("Untitled", geometry);
                            mathModel.setName("MathModel" + (getMdiManager().getNumCreatedDocumentWindows() + 1));
                            hashTable.put("doc", mathModel);
                        }
                    };
                    if (createOption == VCDocument.MATH_OPTION_SPATIAL_EXISTS) {
                        AsynchClientTask task1 = createSelectDocTask(requester);
                        AsynchClientTask task1b = createSelectLoadGeomTask(requester);
                        taskArray = new AsynchClientTask[] { task1, task1b, task2 };
                    } else {
                        taskArray = new AsynchClientTask[] { task2 };
                    }
                    break;
                } else if (createOption == VCDocument.MATH_OPTION_FROMBIOMODELAPP) {
                    AsynchClientTask task1 = new AsynchClientTask("select biomodel application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

                        @Override
                        public void run(Hashtable<String, Object> hashTable) throws Exception {
                            // spatial or non-spatial
                            BioModelInfo bioModelInfo = (BioModelInfo) DialogUtils.getDBTreePanelSelection(requester.getComponent(), getMdiManager().getDatabaseWindowManager().getBioModelDbTreePanel(), "Open", "Select BioModel");
                            if (bioModelInfo != null) {
                                // may throw UserCancelException
                                hashTable.put("bioModelInfo", bioModelInfo);
                            }
                        }
                    };
                    AsynchClientTask task2 = new AsynchClientTask("find sim contexts in biomodel application", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

                        @Override
                        public void run(Hashtable<String, Object> hashTable) throws Exception {
                            // spatial or non-spatial
                            // Get the simContexts in the corresponding BioModel
                            BioModelInfo bioModelInfo = (BioModelInfo) hashTable.get("bioModelInfo");
                            SimulationContext[] simContexts = getDocumentManager().getBioModel(bioModelInfo).getSimulationContexts();
                            if (simContexts != null) {
                                // may throw UserCancelException
                                hashTable.put("simContexts", simContexts);
                            }
                        }
                    };
                    AsynchClientTask task3 = new AsynchClientTask("create math model from biomodel application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

                        @Override
                        public void run(Hashtable<String, Object> hashTable) throws Exception {
                            SimulationContext[] simContexts = (SimulationContext[]) hashTable.get("simContexts");
                            String[] simContextNames = new String[simContexts.length];
                            if (simContextNames.length == 0) {
                                throw new RuntimeException("no application is available");
                            } else {
                                for (int i = 0; i < simContexts.length; i++) {
                                    simContextNames[i] = simContexts[i].getName();
                                }
                                Component component = requester.getComponent();
                                // Get the simContext names, so that user can choose which simContext math to import
                                String simContextChoice = (String) PopupGenerator.showListDialog(component, simContextNames, "Please select Application");
                                if (simContextChoice == null) {
                                    throw UserCancelException.CANCEL_DB_SELECTION;
                                }
                                SimulationContext chosenSimContext = null;
                                for (int i = 0; i < simContexts.length; i++) {
                                    if (simContexts[i].getName().equals(simContextChoice)) {
                                        chosenSimContext = simContexts[i];
                                        break;
                                    }
                                }
                                Objects.requireNonNull(chosenSimContext);
                                BioModelInfo bioModelInfo = (BioModelInfo) hashTable.get("bioModelInfo");
                                // Get corresponding mathDesc to create new mathModel and return.
                                String newName = bioModelInfo.getVersion().getName() + "_" + chosenSimContext.getName();
                                MathDescription bioMathDesc = chosenSimContext.getMathDescription();
                                MathDescription newMathDesc = null;
                                newMathDesc = new MathDescription(newName + "_" + (new Random()).nextInt());
                                newMathDesc.setGeometry(bioMathDesc.getGeometry());
                                newMathDesc.read_database(new CommentStringTokenizer(bioMathDesc.getVCML_database()));
                                newMathDesc.isValid();
                                MathModel newMathModel = new MathModel(null);
                                newMathModel.setName(newName);
                                newMathModel.setMathDescription(newMathDesc);
                                hashTable.put("doc", newMathModel);
                            }
                        }
                    };
                    taskArray = new AsynchClientTask[] { task1, task2, task3 };
                    break;
                } else {
                    throw new RuntimeException("Unknown MathModel Document creation option value=" + documentCreationInfo.getOption());
                }
            }
        case GEOMETRY_DOC:
            {
                if (createOption == VCDocument.GEOM_OPTION_1D || createOption == VCDocument.GEOM_OPTION_2D || createOption == VCDocument.GEOM_OPTION_3D) {
                    // analytic
                    AsynchClientTask task1 = new AsynchClientTask("creating analytic geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

                        @Override
                        public void run(Hashtable<String, Object> hashTable) throws Exception {
                            Geometry geometry = new Geometry("Geometry" + (getMdiManager().getNumCreatedDocumentWindows() + 1), documentCreationInfo.getOption());
                            geometry.getGeometrySpec().addSubVolume(new AnalyticSubVolume("subdomain0", new Expression(1.0)));
                            geometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
                            hashTable.put("doc", geometry);
                        }
                    };
                    taskArray = new AsynchClientTask[] { task1 };
                    break;
                }
                if (createOption == VCDocument.GEOM_OPTION_CSGEOMETRY_3D) {
                    // constructed solid geometry
                    AsynchClientTask task1 = new AsynchClientTask("creating constructed solid geometry", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

                        @Override
                        public void run(Hashtable<String, Object> hashTable) throws Exception {
                            Geometry geometry = new Geometry("Geometry" + (getMdiManager().getNumCreatedDocumentWindows() + 1), 3);
                            Extent extent = geometry.getExtent();
                            if (extent != null) {
                                // create a CSGPrimitive of type cube and scale it to the 'extent' components. Use this as the default or background CSGObject (subdomain).
                                // This can be considered as the equivalent of subdomain (with expression) 1.0 for analyticSubvolume.
                                // basic cube
                                CSGPrimitive cube = new CSGPrimitive("cube", CSGPrimitive.PrimitiveType.CUBE);
                                // scaled cube
                                double x = extent.getX();
                                double y = extent.getY();
                                double z = extent.getZ();
                                CSGScale scaledCube = new CSGScale("scale", new Vect3d(x / 2.0, y / 2.0, z / 2.0));
                                scaledCube.setChild(cube);
                                // translated scaled cube
                                CSGTranslation translatedScaledCube = new CSGTranslation("translation", new Vect3d(x / 2, y / 2, z / 2));
                                translatedScaledCube.setChild(scaledCube);
                                CSGObject csgObject = new CSGObject(null, "subdomain0", 0);
                                csgObject.setRoot(translatedScaledCube);
                                geometry.getGeometrySpec().addSubVolume(csgObject, false);
                                geometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
                                hashTable.put("doc", geometry);
                            }
                        }
                    };
                    taskArray = new AsynchClientTask[] { task1 };
                    break;
                } else {
                    throw new RuntimeException("Unknown Geometry Document creation option value=" + documentCreationInfo.getOption());
                }
            }
        default:
            {
                throw new RuntimeException("Unknown default document type: " + documentCreationInfo.getDocumentType());
            }
    }
    return taskArray;
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) MathModel(cbit.vcell.mathmodel.MathModel) SetMathDescription(cbit.vcell.client.task.SetMathDescription) MathDescription(cbit.vcell.math.MathDescription) Extent(org.vcell.util.Extent) CSGPrimitive(cbit.vcell.geometry.CSGPrimitive) CSGScale(cbit.vcell.geometry.CSGScale) GeometryThumbnailImageFactoryAWT(cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT) Random(java.util.Random) Component(java.awt.Component) CSGObject(cbit.vcell.geometry.CSGObject) CSGTranslation(cbit.vcell.geometry.CSGTranslation) Hashtable(java.util.Hashtable) BioModelInfo(org.vcell.util.document.BioModelInfo) SimulationContext(cbit.vcell.mapping.SimulationContext) ProgrammingException(org.vcell.util.ProgrammingException) GeometryException(cbit.vcell.geometry.GeometryException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) UtilCancelException(org.vcell.util.UtilCancelException) DataFormatException(java.util.zip.DataFormatException) UserCancelException(org.vcell.util.UserCancelException) Vect3d(cbit.vcell.render.Vect3d) Geometry(cbit.vcell.geometry.Geometry) Expression(cbit.vcell.parser.Expression) BioModel(cbit.vcell.biomodel.BioModel) CommentStringTokenizer(org.vcell.util.CommentStringTokenizer) CSGObject(cbit.vcell.geometry.CSGObject) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume)

Aggregations

CSGTranslation (cbit.vcell.geometry.CSGTranslation)7 CSGScale (cbit.vcell.geometry.CSGScale)6 CSGObject (cbit.vcell.geometry.CSGObject)5 CSGRotation (cbit.vcell.geometry.CSGRotation)5 Vect3d (cbit.vcell.render.Vect3d)5 CSGNode (cbit.vcell.geometry.CSGNode)4 CSGPrimitive (cbit.vcell.geometry.CSGPrimitive)4 CSGHomogeneousTransformation (cbit.vcell.geometry.CSGHomogeneousTransformation)3 CSGSetOperator (cbit.vcell.geometry.CSGSetOperator)3 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)2 CSGTransformation (cbit.vcell.geometry.CSGTransformation)2 Geometry (cbit.vcell.geometry.Geometry)2 GeometryThumbnailImageFactoryAWT (cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)2 Expression (cbit.vcell.parser.Expression)2 Component (java.awt.Component)2 ImageException (cbit.image.ImageException)1 BioModel (cbit.vcell.biomodel.BioModel)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 SetMathDescription (cbit.vcell.client.task.SetMathDescription)1 BioModelNode (cbit.vcell.desktop.BioModelNode)1