-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a custom anonymous ObjectIDM class to work with bimserver 1.3 and
allow the serialization/export to a CSV file that can be imported into e.g. spreadsheet applications
- Loading branch information
jakob-beetz
committed
Apr 3, 2014
1 parent
38fdf70
commit 87e4417
Showing
1 changed file
with
121 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,122 @@ | ||
package nl.wietmazairac.bimql; | ||
|
||
import java.util.List; | ||
|
||
import org.antlr.runtime.ANTLRStringStream; | ||
import org.antlr.runtime.CharStream; | ||
import org.antlr.runtime.CommonTokenStream; | ||
import org.antlr.runtime.RecognitionException; | ||
import org.antlr.runtime.TokenStream; | ||
import org.bimserver.emf.IdEObject; | ||
import org.bimserver.emf.IfcModelInterface; | ||
import org.bimserver.emf.IfcModelInterfaceException; | ||
import org.bimserver.plugins.ModelHelper; | ||
import org.bimserver.plugins.Reporter; | ||
import org.bimserver.plugins.queryengine.QueryEngine; | ||
import org.bimserver.plugins.queryengine.QueryEngineException; | ||
|
||
public class BimQLQueryEngine implements QueryEngine { | ||
|
||
@Override | ||
public IfcModelInterface query(IfcModelInterface model, String code, final Reporter reporter, ModelHelper modelHelper) throws QueryEngineException { | ||
CharStream charStream = new ANTLRStringStream(code); | ||
BimQLLexer lexer = new BimQLLexer(charStream) { | ||
@Override | ||
public void reportError(RecognitionException e) { | ||
String hdr = getErrorHeader(e); | ||
String msg = getErrorMessage(e, getTokenNames()); | ||
emitErrorMessage(hdr + " " + msg); | ||
reporter.error(new Exception(hdr + " " + msg)); | ||
} | ||
}; | ||
TokenStream tokenStream = new CommonTokenStream(lexer); | ||
BimQLParser parser = new BimQLParser(tokenStream) { | ||
@Override | ||
public void reportError(RecognitionException e) { | ||
String hdr = getErrorHeader(e); | ||
String msg = getErrorMessage(e, tokenNames); | ||
emitErrorMessage(hdr + " " + msg); | ||
reporter.error(new Exception(hdr + " " + msg)); | ||
} | ||
}; | ||
try { | ||
IfcModelInterface resultModel = modelHelper.getTargetModel(); | ||
List<Object> result = parser.bimql(model); | ||
if (result != null) { | ||
for (Object object : result) { | ||
if (object instanceof IdEObject) { | ||
modelHelper.copy((IdEObject)object); | ||
} | ||
} | ||
} | ||
return resultModel; | ||
} catch (RecognitionException e) { | ||
throw new QueryEngineException(e); | ||
} catch (IfcModelInterfaceException e) { | ||
throw new QueryEngineException(e); | ||
} | ||
} | ||
package nl.wietmazairac.bimql; | ||
|
||
import java.util.List; | ||
|
||
import org.antlr.runtime.ANTLRStringStream; | ||
import org.antlr.runtime.CharStream; | ||
import org.antlr.runtime.CommonTokenStream; | ||
import org.antlr.runtime.RecognitionException; | ||
import org.antlr.runtime.TokenStream; | ||
import org.bimserver.emf.IdEObject; | ||
import org.bimserver.emf.IfcModelInterface; | ||
import org.bimserver.emf.IfcModelInterfaceException; | ||
import org.bimserver.ifc.IfcModel; | ||
import org.bimserver.plugins.ModelHelper; | ||
import org.bimserver.plugins.Reporter; | ||
import org.bimserver.plugins.objectidms.AbstractObjectIDM; | ||
import org.bimserver.plugins.objectidms.ObjectIDM; | ||
import org.bimserver.plugins.queryengine.QueryEngine; | ||
import org.bimserver.plugins.queryengine.QueryEngineException; | ||
import org.eclipse.emf.ecore.EAttribute; | ||
import org.eclipse.emf.ecore.EClass; | ||
import org.eclipse.emf.ecore.EStructuralFeature; | ||
|
||
public class BimQLQueryEngine implements QueryEngine { | ||
|
||
@Override | ||
public IfcModelInterface query(IfcModelInterface model, String code, final Reporter reporter, ModelHelper modelHelper) throws QueryEngineException { | ||
CharStream charStream = new ANTLRStringStream(code); | ||
BimQLLexer lexer = new BimQLLexer(charStream) { | ||
@Override | ||
public void reportError(RecognitionException e) { | ||
String hdr = getErrorHeader(e); | ||
String msg = getErrorMessage(e, getTokenNames()); | ||
emitErrorMessage(hdr + " " + msg); | ||
reporter.error(new Exception(hdr + " fault " + msg)); | ||
} | ||
}; | ||
TokenStream tokenStream = new CommonTokenStream(lexer); | ||
BimQLParser parser = new BimQLParser(tokenStream) { | ||
@Override | ||
public void reportError(RecognitionException e) { | ||
String hdr = getErrorHeader(e); | ||
String msg = getErrorMessage(e, tokenNames); | ||
emitErrorMessage(hdr + " threw this " + msg); | ||
reporter.error(new Exception(hdr + " " + msg)); | ||
} | ||
}; | ||
try { | ||
// IfcModelInterface resultModel = modelHelper.getTargetModel(); | ||
// resultModel.clear(); | ||
IfcModelInterface resultModel = new IfcModel(); | ||
AbstractObjectIDM idm = new AbstractObjectIDM(null){ | ||
|
||
@Override | ||
public boolean shouldFollowReference(EClass originalClass, | ||
EClass eClass, EStructuralFeature eStructuralFeature) { | ||
// System.out.println(eStructuralFeature.getName()); | ||
if (eStructuralFeature instanceof EAttribute) | ||
return true; | ||
if (eStructuralFeature.getName().equalsIgnoreCase("HasAssignments")) | ||
return true; | ||
if (eStructuralFeature.getName().equalsIgnoreCase("HasAssociations")) | ||
return true; | ||
if (eStructuralFeature.getName().equalsIgnoreCase("IsDefinedBy")) | ||
return true; | ||
if (eStructuralFeature.getName().equalsIgnoreCase("RelatingPropertyDefinition")) | ||
return true; | ||
if (eStructuralFeature.getName().equalsIgnoreCase("HasProperties")) | ||
return true; | ||
if (eStructuralFeature.getName().equalsIgnoreCase("NominalValue")) | ||
return true; | ||
if (eStructuralFeature.getName().equalsIgnoreCase("Quantities")) | ||
return true; | ||
if (eStructuralFeature.getName().equalsIgnoreCase("wrappedValue")) | ||
return true; | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean shouldIncludeClass(EClass originalClass, | ||
EClass eClass) { | ||
// TODO Auto-generated method stub | ||
return true; | ||
} | ||
|
||
}; | ||
|
||
ModelHelper mh = new ModelHelper(idm,resultModel); | ||
mh.setKeepOriginalOids(false); | ||
|
||
mh.setTargetModel(resultModel); | ||
|
||
// for (IdEObject obj : resultModel.getObjects().values()) | ||
// { | ||
// resultModel.remove(obj); | ||
// } | ||
List<Object> result = parser.bimql(model); | ||
if (result != null) { | ||
for (Object object : result) { | ||
if (object instanceof IdEObject) { | ||
// resultModel.add(1,((IdEObject)object)); | ||
mh.copy((IdEObject)object); | ||
for (EStructuralFeature feature : ((IdEObject)object).eClass().getEAllStructuralFeatures()) | ||
{ | ||
if (feature.getName().equalsIgnoreCase("HasAssociations")) | ||
{ | ||
Object eGet = ((IdEObject)object).eGet(feature); | ||
// System.out.println(eGet.toString()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return resultModel; | ||
// return mh.getTargetModel(); | ||
} catch (RecognitionException e) { | ||
throw new QueryEngineException(e); | ||
} catch (IfcModelInterfaceException e) { | ||
throw new QueryEngineException(e); | ||
} | ||
} | ||
} |