DGP - added isCompatible checks for all Rocksim components
[debian/openrocket] / src / net / sf / openrocket / file / rocksim / BaseHandler.java
index 700c2f9bdbcec4b38795d45b017d9bb932c35b93..c4e9c11e403efadd9d9cbf6fe1f4526b33587d1c 100644 (file)
@@ -180,6 +180,26 @@ public abstract class BaseHandler<C extends RocketComponent> extends ElementHand
         materialName = content;
     }
 
+    /**
+     * Add child to parent only if the child is compatible.  Otherwise add to warning set.
+     * 
+     * @param parent  the parent component
+     * @param child   the child component
+     * @param warnings the warning set
+     * 
+     * @return true if the child is compatible with parent
+     */
+    protected static boolean isCompatible(RocketComponent parent, Class<? extends RocketComponent> child, WarningSet warnings) {
+        if (!parent.isCompatible(child)) {
+            warnings.add(child.getName() + " can not be attached to "
+                         + parent.getComponentName() + ", ignoring component.");
+            return false;
+        }
+        else {
+            return true;
+        }
+    }
+    
     /**
      * Create a custom material based on the density.
      *