# cee::ug::DataSource

class `DataSource` : public RefCountedObject

  The data source of the model.

  For instance a file interface or custom built by the user.

  The data source contains a collection of all states for one analysis. Each state groups together geometries and results for one time step, load case, frequency etc.

  Each unstructured grid model owns one data source.

  DataSource is the parent class for all data sources and cannot be instantiated. DataSource contains general functions that applies to all data source types. To create a data source, use one of the subclassed versions. The data source can, for instance, be read from a supported interface or be created “by hand” from within the application.

  See DataSourceInterface and DataSourceMemory.

  The data source also has a directory describing the metadata for this model (DataSourceDirectory). This metadata is mostly used by the interface system.

  The data source is identified with a unique id set upon construction of the object. Use id() to get the id of an existing data source.

  States and directory is managed from the inherited data source classes and the main DataSource class only contains const function for querying state and directory. Get number of states using stateCount() and access individual states by calling state() with the requested state index. (For convenience, the stateIndex() function is available to convert from a state id to a state index).

  In addition DataSource offers the isDataSourceValid() function to check if the data source content matches the metadata.

  A DataSource has a collection of DataElementSet. These element sets are groups of elements from from different parts and geometries within the DataSource. The element sets can be used for specifying which elements that should be visible. The sets to use for filtering are specified in the ModelSpec::setVisibleSetIds() method.

  Example - Creating a memory data source

  Example on building your data source and geometry.

  Create a model and a memory data source. The constructor of the data source takes a unique id and the number of geometries (here 1). Set the data source in the created model.

      cee::PtrRef<cee::ug::UnstructGridModel> ugModel = new cee::ug::UnstructGridModel();
      cee::PtrRef<cee::ug::DataSourceMemory> dataSource = new cee::ug::DataSourceMemory(1, 1);
      ugModel->setDataSource(dataSource.get());

  Create the state. Set number of geometries to 1 in the constructor.

      int stateId = 1;
      cee::PtrRef<cee::ug::DataState> state = new cee::ug::DataState(stateId, 1);
      dataSource->addState(state.get());

  See the complete source code at: UnstructGrid: Simple Model with Two Triangles

  Example - Reading model from file

  Example on reading a model from a file interface.

  Create the model and VTFx file interface data source.

  Give the data source a unique id.

      cee::PtrRef<cee::ug::UnstructGridModel> ugModel = new cee::ug::UnstructGridModel();
      cee::PtrRef<cee::ug::DataSourceVTFx> source = new cee::ug::DataSourceVTFx(42);

  Open the test file (contact.vtfx) included in the tutorial data files. The open() function will return true if the file was opened successfully.

  Set the data source in the model.

      cee::Str vtfxFile = TutorialUtils::testDataDir() + "contact.vtfx";
      if (!source->open(vtfxFile))
      {
          // VTFx file not found
          return;
      }
      ugModel->setDataSource(source.get());

  If the file was read successfully, you will now have a complete data source with one or more states.

  State info and other metadata will be available through the data source’s directory.

  See the complete source code at: UnstructGrid: Load Model from File and Set Up Model Specification

  Tutorials

  - UnstructGrid: Simple Model with Two Triangles
  - UnstructGrid: A Simple Model with Results
  - UnstructGrid: Load Model from File and Set Up Model Specification

  See also

  DataSourceInterface, DataSourceMemory, DataState, and DataSourceDirectory

  Subclassed by DataSourceInterface, DataSourceMemory

  Public Functions

  int `id`() const

    Returns the id of the data source.

  size_t `stateCount`() const

    Returns number of states for the data source.

  size_t `stateIndex`(int stateId) const

    Returns the index of the state with id stateId.

    Returns cee::UNDEFINED_SIZE_T if the state id was not found.

  size_t `geometryCountPerState`() const

    Returns the number of geometries (per state) in the DataSource.

  const DataState *`state`(size_t stateIndex) const

    Returns the state at the given state index.

  DataState *`state`(size_t stateIndex)

    Returns the state at the given state index.

  const DataState *`currentState`(const UnstructGridModel *model) const

    Returns the current state (the state in the current frame) in the given model.

    Returns NULL if no current state

  DataState *`currentState`(const UnstructGridModel *model)

    Returns the current state (the state in the current frame) in the given model.

    Returns NULL if no current state

  const DataSourceDirectory *`directory`() const

    Returns the data directory of the data source.

    The directory is a table of contents of the data source, indicating (possible) content. If the data source is not of type DataSourceReader, the directory should reflect the current content.

  DataSourceDirectory *`directory`()

    Returns the data directory of the data source.

    The directory is a table of contents of the data source, indicating (possible) content. If the data source is not of type DataSourceReader, the directory should reflect the current content.

  const DataElementSet *`elementSet`(size_t setIndex) const

    Returns a const ptr to the element set at the given index.

  DataElementSet *`elementSet`(size_t setIndex)

    Returns the element set at the given index.

  size_t `elementSetCount`() const

    Returns the number of DataElementSets in this data source.

  size_t `elementSetIndex`(int setId) const

    Returns the index of the element set with the given id.

  void `addElementSet`(DataElementSet *elementSet)

    Adds an element set to this data source.

    A DataElementSet is used to create a group of elements (from different parts and geometries) which can be used for visual filtering (using the ModelSpec::setVisibleSetIds() method).

  void `removeElementSet`(const DataElementSet *elementSet)

    Removes an element set from this data source.

    See also

    addElementSet

  void `removeAllElementSets`()

    Removes all element sets from the data source.

    See also

    addElementSet

  bool `isDataSourceValid`(Str *failReason) const

    Validates that the data source contents matches the metadata.

    The failReason string will contain an error description if validation failed.

  int `defaultDisplacementResultId`() const

    Returns the default displacement result id, if any, for the data source.

    Returns -1 if there is no default result id

  bool `computeCustomResults`(int stateId, const DataStateSpec &stateSpec)

    Computes custom results.

Conversation saved
HOOPSY BETA

### Hello! I'm HOOPSY

Your Docs generative AI assistant. Ask me anything about HOOPS Envision for Desktop or choose a sample question below to start a conversation:

What is HOOPS Envision for Desktop?
What are the latest release notes for HOOPS Envision for Desktop?
How do I start evaluating HOOPS Envision for Desktop?
How do I write my first sample application?
How can I get assistance?

HOOPSY may store conversations according to OpenAI's policy. Responses may not always be accurate.

HOOPSY is thinking...