Find Material of IPersistentEntity - xbim

I have list of IPersistEntity instances, that can be meshed, it means each of them implements one of these interfaces: IIfcFaceBasedSurfaceModel, IIfcShellBasedSurfaceModel, IIfcConnectedFaceSet, IIfcTriangulatedFaceSet, IIfcFacetedBrep.
And I want to find for each of this instance corresponding IIfcMaterial or IIfcSurfaceStyle.
I spend good amount of time digging in the repository but didn't find the way to do this. Will appreciate any help.

You can try to convert your entities to IfcObjectDefinition, you'll be able to get the material from there.
foreach (var entity in entities)
{
var definition = entity as IfcObjectDefinition;
var material = definition.Material as IIfcMaterial;
}

Related

How to sort List in Strintemplate (v4)?

Here is what I try to achieve:
In my Java code, at some place a Map (may be a HashMap) is created, that may not be sorted:
var map = Map.of("c","third entry","a","first entry","b","second entry");
var data = Map.of("map",map);
Later this map is passed to a stringtemplate loaded from a file with content similar to this:
delimiters "«", "»"
template(data) ::= <<
«data.map.keys:{key|• «data.map.(key)»}; separator="\n"»
>>
However, I want the generated list to be sorted by map key, but there seems to be no function like sort(list). Can I achieve what I want?
desired:
«sorted(data.map.keys):{key|• «data.map.(key)»}; separator="\n"»
I googled for this functionality for some time and I really wonder, whether nobody had wanted sorted lists before.
Of course, I could solve it by passing an extra (sorted) list of keys. But is there a straightforward approach?
best wishes :)

How to connect a LookupTable on a Grid with VTK

I’m trying to connect a LookupTable on a Grid(like one from examples). I have seen some tutorial and I have done what was in there, but it still not working.
I have defined a new lookup table like this
vtkSmartPointer<vtkLookupTable> lut =
vtkSmartPointer<vtkLookupTable>::New();
lut->SetNumberOfTableValues(x.size() * y.size());
lut->SetTableValue(0, colors->GetColor4d("Orange").GetData());
lut->Build();
and connected with the grid through the mapper, like this
rgridMapper->SetLookupTable(lut);
rgridMapper->SetUseLookupTableScalarRange(true);
rgridMapper->SetScalarModeToUsePointData();
Anyway it’s still not working. Why is it happening? How could I set a lookup table on a grid? Thanks
I use vtk python for programing,
My idea is that
You need to use rgrigdMapper.SetScalarRange(minValue,maxValue)
Here, the min and max value are the lower and upper limitation of the points color data. Usually, this data is set by vtkFloatArray and deliver to points by vtkPolyData.GetPointData().SetScalars(points)

Compare values with a static and global table in C++

I am working on statistical analyses in my field, and using c++. I am implementing several tests, and some of them need to compare the calculated value with a table, say a distribution table for example, like this one.
I want my different functions in my different classes to be able to access a specific value, to evaluate the significance of my result, for example something like this:
float F = fisherTest(serie1, serie2);
auto tableValue = findValue(serie1.size(), serie2.size());
if(tableValue < F) {
cout << "Not significant";
return -1;
}
This is just an example, as this test actually makes no sense. But I just want to be able to read values from a predefined table.
Do you have an idea of how I can achieve this? Can I store this in a "resource file"?
I hope my question is clear! Thank you.
You can have some data files and pass a configuration during startup (e.g. commandline) to the application so it can find the files and read them. The data structure can then be fed to the test.
It is possible to get the predefined data from several sources:
Hard coded tables in your program.
One or more functions that can compute the data on demand.
Files on your local disk.
Data stored in a database server.
You and your team need to decide which makes the most sense for your application.

RhinoMocks equivalent of Return.CloneOf in NMock

We have a NextInterestDate property on a rhinomock that we initially set to 31/03/2000. This property is accessed and this date is used in the processing of interest calculations for March. Once the March processing is complete the property needs to be updated to be the next chronological interest date which is 30/04/2000.
The next time around the loop we want the mock to return the April end date when the NextInterestDate is accessed on the mock. In short a new date is recalculated each time around the loop and the property on the mock is reassigned with the new date.
This means that the date on the mock must be updated each time around the loop.
What we are seeing however is that the date remains at 31/03/2000 rather than be updated correctly.
We are relatively new to RhinoMocks but we much prefer it to NMocks, albeit there seems to be a steep learning curve.
To solve this problem the previous developer used NMock and used a clonable class that she utilised NMocks ...Return.CloneOF which allowed the mock to be able to update the mock and supply the new value.
We just can't seem to figure out the correct syntax / or a way to achieve this.
Many thanks in advance Regards Colin
You can achieve that with .WhenCalled method. This might seem dodgy, but does exactly the thing you want to:
var expectedDates = new[]
{
new DateTime(2000, 3, 31),
new DateTime(2000, 4, 30),
new DateTime(2000, 5, 31),
};
var invocationsCount = 0;
service.Expect(s => s.NextInterestDate)
.WhenCalled(m => m.ReturnValue = expectedDates[invocationNumber++])
.Return(default(DateTime));
What code above does is simply takes next element from expectedDates array with each successive invocation. The strange call to Return(default(DateTime)) at the end must be there (otherwise Rhino will complain). You shouldn't worry tho - fake return value is ignored when we already specify one with WhenCalled.
Note that you need to be careful with code like one above (incrementing counters, arrays - all that in mock setup). Readability is not the greatest, so having proper variables/test method naming is crucial.

Unit testing data flow in a ssis package

Is there a way to unit test data flow in a ssis package .
Ex: testing the sort - verify that the sort is porperly done.
There is an unit testing framework for SSIS - see SSISUnit.
This is worth looking at but it may not solve your problem. It is possible to unit test individual components at the control flow level using this framework, but it is not possible to isolate and individual Data Flow Transformations - you can only test the whole Data Flow component.
One approach you could take is to redesign your package and break down your DataFlow component into multiple DataFlow components that can be individually tested. However that will impact the performance of your package, because you will have to persist the data somewhere in between each data flow task.
You can also adopt this approach by using NUnit or a similar framework, using the SSIS api to load a package and execute an individual task.
SSISTester can tap data flow between two components and save the data into a file. Output can be accessed in a unit test. For more information look at ssistester.bytesoftwo.com.An example how to use SSISTester to achieve this is given bellow:
[UnitTest("DEMO", "CopyCustomers.dtsx", DisableLogging=true)]
[DataTap(#"\[CopyCustomers]\[DFT Convert customer names]\[RCNT Count customers]", #"\[CopyCustomers]\[DFT Convert customer names]\[DER Convert names to upper string]")]
[DataTap(#"\[CopyCustomers]\[DFT Convert customer names]\[DER Convert names to upper string]", #"\[CopyCustomers]\[DFT Convert customer names]\[FFD Customers converted]")]
public class CopyCustomersFileAll : BaseUnitTest
{
...
protected override void Verify(VerificationContext context)
{
ReadOnlyCollection<DataTap> dataTaps = context.DataTaps;
DataTap dataTap = dataTaps[0];
foreach (DataTapSnapshot snapshot in dataTap.Snapshots)
{
string data = snapshot.LoadData();
}
DataTap dataTap1 = dataTaps[1];
foreach (DataTapSnapshot snapshot in dataTap1.Snapshots)
{
string data = snapshot.LoadData();
}
}
}
Short answer - not easily. Longer answer: yes, but you'll need lots of external tools to do it. One potential test would be to take a small sample of the data set, run it through your sort, and dump to an excel file. Take the same data set, copy it to an excel spreadsheet, and manually sort it. Run a binary diff tool on the result of the dump from SSIS and your hand-sorted example. If everything checks out, it's right.
OTOH, unit testing the Sort in SSIS shouldn't be necessary, unless what you're really testing is the sort criteria selection. The sort should have been tested by MS before it was shipped.
I would automate the testing by having a known good file for appropriate inputs which is compared binarily with an external program.
I like to use data viewers when I need to see the data moving from component to component.