QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsmeshdatasetgroupstore.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmeshdatasetgroupstore.cpp
3  ---------------------
4  begin : June 2020
5  copyright : (C) 2020 by Vincent Cloarec
6  email : vcloarec at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
19 #include "qgsmeshlayer.h"
20 #include "qgsmeshlayerutils.h"
21 #include "qgsapplication.h"
23 
24 
26 {
27  return mRegistery.keys();
28 }
29 
31 {
32  return mRegistery.count();
33 }
34 
36 {
37  return mExtraDatasets->datasetGroupCount();
38 }
39 
41  mLayer( layer ),
42  mExtraDatasets( new QgsMeshExtraDatasetStore ),
43  mDatasetGroupTreeRootItem( new QgsMeshDatasetGroupTreeItem )
44 {}
45 
47 {
48  removePersistentProvider();
49  mPersistentProvider = provider;
50  if ( !mPersistentProvider )
51  return;
52  connect( mPersistentProvider, &QgsMeshDataProvider::datasetGroupsAdded, this, &QgsMeshDatasetGroupStore::onPersistentDatasetAdded );
53  onPersistentDatasetAdded( mPersistentProvider->datasetGroupCount() );
54 }
55 
56 QgsMeshDatasetGroupStore::DatasetGroup QgsMeshDatasetGroupStore::datasetGroup( int index ) const
57 {
58  if ( mRegistery.contains( index ) )
59  return mRegistery[index];
60  else
61  return DatasetGroup{nullptr, -1};
62 }
63 
65 {
66  if ( !mPersistentProvider )
67  return false;
68  return mPersistentProvider->addDataset( path ) ;
69 }
70 
72 {
73  if ( !mPersistentProvider || !mExtraDatasets )
74  return false;
75 
76  switch ( group->dataType() )
77  {
79  if ( ! group->checkValueCountPerDataset( mPersistentProvider->faceCount() ) )
80  return false;
81  break;
83  if ( ! group->checkValueCountPerDataset( mPersistentProvider->vertexCount() ) )
84  return false;
85  break;
87  return false; // volume not supported for extra dataset
88  break;
90  if ( ! group->checkValueCountPerDataset( mPersistentProvider->edgeCount() ) )
91  return false;
92  break;
93  }
94 
95  int nativeIndex = mExtraDatasets->addDatasetGroup( group );
96  int groupIndex = registerDatasetGroup( DatasetGroup{mExtraDatasets.get(), nativeIndex} );
97  QList<int> groupIndexes;
98  groupIndexes.append( groupIndex );
99  createDatasetGroupTreeItems( groupIndexes );
100  syncItemToDatasetGroup( groupIndex );
101 
102  emit datasetGroupsAdded( groupIndexes );
103 
104  return true;
105 }
106 
108 {
109  mDatasetGroupTreeRootItem.reset( new QgsMeshDatasetGroupTreeItem );
110  createDatasetGroupTreeItems( datasetGroupIndexes() );
111  QList<int> groupIndexes = datasetGroupIndexes();
112  for ( int groupIndex : groupIndexes )
113  syncItemToDatasetGroup( groupIndex );
114 }
115 
117 {
118  return mDatasetGroupTreeRootItem.get();
119 }
120 
122 {
123  if ( rootItem )
124  mDatasetGroupTreeRootItem.reset( rootItem->clone() );
125  else
126  mDatasetGroupTreeRootItem.reset();
127 
128  unregisterGroupNotPresentInTree();
129 }
130 
132 {
133  QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.group() );
134  if ( group.first )
135  return group.first->datasetGroupMetadata( group.second );
136  else
138 }
139 
140 int QgsMeshDatasetGroupStore::datasetCount( int groupIndex ) const
141 {
142  QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( groupIndex );
143  if ( group.first )
144  return group.first->datasetCount( group.second );
145  else
146  return 0;
147 }
148 
150 {
151  QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.group() );
152  if ( group.first )
153  return group.first->datasetMetadata( QgsMeshDatasetIndex( group.second, index.dataset() ) );
154  else
155  return QgsMeshDatasetMetadata();
156 }
157 
159 {
160  QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.group() );
161  if ( group.first )
162  return group.first->datasetValue( QgsMeshDatasetIndex( group.second, index.dataset() ), valueIndex );
163  else
164  return QgsMeshDatasetValue();
165 }
166 
167 QgsMeshDataBlock QgsMeshDatasetGroupStore::datasetValues( const QgsMeshDatasetIndex &index, int valueIndex, int count ) const
168 {
169  QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.group() );
170  if ( group.first )
171  return group.first->datasetValues( QgsMeshDatasetIndex( group.second, index.dataset() ), valueIndex, count );
172  else
173  return QgsMeshDataBlock();
174 }
175 
177 {
178  QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.group() );
179  if ( group.first )
180  return group.first->dataset3dValues( QgsMeshDatasetIndex( group.second, index.dataset() ), faceIndex, count );
181  else
182  return QgsMesh3dDataBlock();
183 }
184 
186 {
187  QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.group() );
188  if ( group.first )
189  return group.first->areFacesActive( QgsMeshDatasetIndex( group.second, index.dataset() ), faceIndex, count );
190  else
191  return QgsMeshDataBlock();
192 }
193 
194 bool QgsMeshDatasetGroupStore::isFaceActive( const QgsMeshDatasetIndex &index, int faceIndex ) const
195 {
196  QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.group() );
197  if ( group.first )
198  return group.first->isFaceActive( QgsMeshDatasetIndex( group.second, index.dataset() ), faceIndex );
199  else
200  return false;
201 }
202 
204  qint64 time,
206 {
207  QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( groupIndex );
208  if ( !group.first )
209  return QgsMeshDatasetIndex();
210 
211  const QDateTime &referenceTime = mPersistentProvider->temporalCapabilities()->referenceTime();
212 
213  return QgsMeshDatasetIndex( groupIndex,
214  group.first->datasetIndexAtTime( referenceTime, group.second, time, method ).dataset() );
215 }
216 
218 {
219  QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.group() );
220  if ( !group.first || group.second < 0 )
221  return INVALID_MESHLAYER_TIME;
222 
223  QgsMeshDatasetIndex nativeIndex( group.second, index.dataset() );
224 
225  if ( group.first == mPersistentProvider )
226  return mPersistentProvider->temporalCapabilities()->datasetTime( nativeIndex );
227  else if ( group.first == mExtraDatasets.get() )
228  return mExtraDatasets->datasetRelativeTime( nativeIndex );
229 
230  return INVALID_MESHLAYER_TIME;
231 
232 }
233 
235 {
236  return ( mPersistentProvider && mPersistentProvider->temporalCapabilities()->hasTemporalCapabilities() ) ||
237  ( mExtraDatasets && mExtraDatasets->hasTemporalCapabilities() );
238 }
239 
240 QDomElement QgsMeshDatasetGroupStore::writeXml( QDomDocument &doc, const QgsReadWriteContext &context )
241 {
242  Q_UNUSED( context );
243  QDomElement storeElement = doc.createElement( QStringLiteral( "mesh-dataset-groups-store" ) );
244  storeElement.appendChild( mDatasetGroupTreeRootItem->writeXml( doc, context ) );
245 
246  QMap < int, DatasetGroup>::const_iterator it = mRegistery.begin();
247  while ( it != mRegistery.end() )
248  {
249  QDomElement elemDataset;
250  if ( it.value().first == mPersistentProvider )
251  {
252  elemDataset = doc.createElement( QStringLiteral( "mesh-dataset" ) );
253  elemDataset.setAttribute( QStringLiteral( "global-index" ), it.key() );
254  elemDataset.setAttribute( QStringLiteral( "source-type" ), QStringLiteral( "persitent-provider" ) );
255  elemDataset.setAttribute( QStringLiteral( "source-index" ), it.value().second );
256 
257  }
258  else if ( it.value().first == mExtraDatasets.get() )
259  {
260  QgsMeshDatasetGroupTreeItem *item = mDatasetGroupTreeRootItem->childFromDatasetGroupIndex( it.key() );
261  if ( item )
262  {
263  elemDataset = mExtraDatasets->writeXml( it.value().second, doc, context );
264  if ( !elemDataset.isNull() )
265  elemDataset.setAttribute( QStringLiteral( "global-index" ), it.key() );
266  }
267  }
268 
269  if ( !elemDataset.isNull() )
270  storeElement.appendChild( elemDataset );
271  ++it;
272  }
273 
274  return storeElement;
275 }
276 
277 void QgsMeshDatasetGroupStore::readXml( const QDomElement &storeElem, const QgsReadWriteContext &context )
278 {
279  Q_UNUSED( context );
280  mRegistery.clear();
281  QDomElement datasetElem = storeElem.firstChildElement( "mesh-dataset" );
282  QMap<int, QgsMeshDatasetGroup *> extraDatasetGroups;
283  while ( !datasetElem.isNull() )
284  {
285  int globalIndex = datasetElem.attribute( QStringLiteral( "global-index" ) ).toInt();
286  int sourceIndex;
287  QgsMeshDatasetSourceInterface *source = nullptr;
288  if ( datasetElem.attribute( QStringLiteral( "source-type" ) ) == QLatin1String( "persitent-provider" ) )
289  {
290  source = mPersistentProvider;
291  sourceIndex = datasetElem.attribute( QStringLiteral( "source-index" ) ).toInt();
292  }
293  else if ( datasetElem.attribute( QStringLiteral( "source-type" ) ) == QLatin1String( "virtual" ) )
294  {
295  source = mExtraDatasets.get();
296  QString name = datasetElem.attribute( QStringLiteral( "name" ) );
297  QString formula = datasetElem.attribute( QStringLiteral( "formula" ) );
298  qint64 startTime = datasetElem.attribute( QStringLiteral( "start-time" ) ).toLongLong();
299  qint64 endTime = datasetElem.attribute( QStringLiteral( "end-time" ) ).toLongLong();
300 
301  QgsMeshDatasetGroup *dsg = new QgsMeshVirtualDatasetGroup( name, formula, mLayer, startTime, endTime );
302  extraDatasetGroups[globalIndex] = dsg;
303  sourceIndex = mExtraDatasets->addDatasetGroup( dsg );
304  }
305 
306  if ( source )
307  mRegistery[globalIndex] = DatasetGroup{source, sourceIndex};
308 
309  datasetElem = datasetElem.nextSiblingElement( QStringLiteral( "mesh-dataset" ) );
310  }
311 
312  QDomElement rootTreeItemElem = storeElem.firstChildElement( QStringLiteral( "mesh-dataset-group-tree-item" ) );
313  if ( !rootTreeItemElem.isNull() )
314  setDatasetGroupTreeItem( new QgsMeshDatasetGroupTreeItem( rootTreeItemElem, context ) );
315 
316  checkDatasetConsistency( mPersistentProvider );
317  removeUnregisteredItemFromTree();
318 
319  //Once everything is created, initialize the extra dataset groups
320  for ( int groupIndex : extraDatasetGroups.keys() )
321  extraDatasetGroups.value( groupIndex )->initialize();
322 
323 
324  mExtraDatasets->updateTemporalCapabilities();
325 }
326 
327 bool QgsMeshDatasetGroupStore::saveDatasetGroup( QString filePath, int groupIndex, QString driver )
328 {
329  DatasetGroup group = datasetGroup( groupIndex );
330 
331  bool fail = true;
332  if ( group.first && group.second >= 0 )
333  fail = mPersistentProvider->persistDatasetGroup( filePath, driver, group.first, group.second );
334 
335  if ( !fail )
336  {
337  eraseDatasetGroup( group );
338  group.first = mPersistentProvider;
339  group.second = mPersistentProvider->datasetGroupCount() - 1;
340  mRegistery[groupIndex] = group;
341  //update the item type
342  if ( mDatasetGroupTreeRootItem )
343  {
344  QgsMeshDatasetGroupTreeItem *item = mDatasetGroupTreeRootItem->childFromDatasetGroupIndex( groupIndex );
345  if ( item )
346  item->setPersistentDatasetGroup( filePath );
347  }
348  }
349 
350  return fail;
351 }
352 
353 void QgsMeshDatasetGroupStore::onPersistentDatasetAdded( int count )
354 {
355  Q_ASSERT( mPersistentProvider );
356 
357  int providerTotalCount = mPersistentProvider->datasetGroupCount();
358  int providerBeginIndex = mPersistentProvider->datasetGroupCount() - count;
359  QList<int> groupIndexes;
360  for ( int i = providerBeginIndex; i < providerTotalCount; ++i )
361  groupIndexes.append( registerDatasetGroup( DatasetGroup{mPersistentProvider, i} ) );
362 
363  createDatasetGroupTreeItems( groupIndexes );
364  for ( int groupIndex : groupIndexes )
365  syncItemToDatasetGroup( groupIndex );
366 
367  emit datasetGroupsAdded( groupIndexes );
368 }
369 
370 void QgsMeshDatasetGroupStore::removePersistentProvider()
371 {
372  if ( !mPersistentProvider )
373  return;
374 
375  disconnect( mPersistentProvider, &QgsMeshDataProvider::datasetGroupsAdded, this, &QgsMeshDatasetGroupStore::onPersistentDatasetAdded );
376 
377  QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
378  while ( it != mRegistery.end() )
379  {
380  if ( it.value().first == mPersistentProvider )
381  it = mRegistery.erase( it );
382  else
383  ++it;
384  }
385 
386  mPersistentProvider = nullptr;
387 }
388 
389 int QgsMeshDatasetGroupStore::newIndex()
390 {
391  int index = 0;
392  QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
393  while ( it != mRegistery.end() )
394  {
395  if ( index <= it.key() )
396  index = it.key() + 1;
397  ++it;
398  }
399  return index;
400 }
401 
402 int QgsMeshDatasetGroupStore::registerDatasetGroup( const QgsMeshDatasetGroupStore::DatasetGroup &group )
403 {
404  int groupIndex = newIndex();
405  mRegistery[newIndex()] = group;
406  return groupIndex;
407 }
408 
409 void QgsMeshDatasetGroupStore::eraseDatasetGroup( const QgsMeshDatasetGroupStore::DatasetGroup &group )
410 {
411  if ( group.first == mPersistentProvider )
412  return; //removing persistent dataset group from the store is not allowed
413  else if ( group.first == mExtraDatasets.get() )
414  eraseExtraDataset( group.second );
415 }
416 
417 void QgsMeshDatasetGroupStore::eraseExtraDataset( int indexInExtraStore )
418 {
419  mExtraDatasets->removeDatasetGroup( indexInExtraStore );
420 
421  //search dataset with index greater than indexInExtraStore and decrement it
422  QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
423  while ( it != mRegistery.end() )
424  {
425  int localIndex = it.value().second;
426  if ( it.value().first == mExtraDatasets.get() && localIndex > indexInExtraStore )
427  it->second = localIndex - 1;
428  ++it;
429  }
430 }
431 
432 int QgsMeshDatasetGroupStore::nativeIndexToGroupIndex( QgsMeshDatasetSourceInterface *source, int nativeIndex )
433 {
434  QMap < int, DatasetGroup>::const_iterator it = mRegistery.begin();
435  while ( it != mRegistery.end() )
436  {
437  if ( it.value() == DatasetGroup{source, nativeIndex} )
438  return it.key();
439  ++it;
440  }
441  return -1;
442 }
443 
444 void QgsMeshDatasetGroupStore::checkDatasetConsistency( QgsMeshDatasetSourceInterface *source )
445 {
446  // check if datasets of source are present, if not, add them
447  QList<int> indexes;
448  for ( int i = 0; i < source->datasetGroupCount(); ++i )
449  if ( nativeIndexToGroupIndex( source, i ) == -1 )
450  indexes.append( registerDatasetGroup( DatasetGroup{source, i} ) );
451 
452  if ( !indexes.isEmpty() )
453  createDatasetGroupTreeItems( indexes );
454  for ( int index : indexes )
455  syncItemToDatasetGroup( index );
456 }
457 
458 void QgsMeshDatasetGroupStore::removeUnregisteredItemFromTree()
459 {
460  QList<QgsMeshDatasetGroupTreeItem *> itemsToCheck;
461  QList<int> indexItemToRemove;
462  for ( int i = 0; i < mDatasetGroupTreeRootItem->childCount(); ++i )
463  itemsToCheck.append( mDatasetGroupTreeRootItem->child( i ) );
464 
465  while ( !itemsToCheck.isEmpty() )
466  {
467  QgsMeshDatasetGroupTreeItem *item = itemsToCheck.takeFirst();
468  int globalIndex = item->datasetGroupIndex();
469  if ( !mRegistery.contains( globalIndex ) )
470  indexItemToRemove.append( globalIndex );
471  for ( int i = 0; i < item->childCount(); ++i )
472  itemsToCheck.append( item->child( i ) );
473  }
474 
475  for ( int i : indexItemToRemove )
476  {
477  QgsMeshDatasetGroupTreeItem *item = mDatasetGroupTreeRootItem->childFromDatasetGroupIndex( i );
478  if ( item )
479  item->parentItem()->removeChild( item );
480  }
481 }
482 
483 void QgsMeshDatasetGroupStore::unregisterGroupNotPresentInTree()
484 {
485  if ( !mDatasetGroupTreeRootItem )
486  {
487  mRegistery.clear();
488  return;
489  }
490 
491  QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
492  while ( it != mRegistery.end() )
493  {
494  DatasetGroup datasetGroup = it.value();
495  int globalIndex = it.key();
496  if ( ! mDatasetGroupTreeRootItem->childFromDatasetGroupIndex( globalIndex ) // Not in the tree item
497  && datasetGroup.first != mPersistentProvider ) // and not persistent
498  {
499  it = mRegistery.erase( it ); //remove from registery
500  eraseDatasetGroup( datasetGroup ); //remove from where the dataset group is stored
501  }
502  else
503  ++it;
504  }
505 }
506 
507 void QgsMeshDatasetGroupStore::syncItemToDatasetGroup( int groupIndex )
508 {
509  if ( !mDatasetGroupTreeRootItem )
510  return;
511  DatasetGroup group = datasetGroup( groupIndex );
512  QgsMeshDatasetGroupTreeItem *item = mDatasetGroupTreeRootItem->childFromDatasetGroupIndex( groupIndex );
513  if ( group.first == mPersistentProvider && mPersistentProvider )
514  {
515  QgsMeshDatasetGroupMetadata meta = mPersistentProvider->datasetGroupMetadata( group.second );
516  if ( item )
517  item->setPersistentDatasetGroup( meta.uri() );
518  }
519  else if ( group.first == mExtraDatasets.get() )
520  {
521  if ( item )
522  item->setDatasetGroup( mExtraDatasets->datasetGroup( group.second ) );
523  }
524 }
525 
526 void QgsMeshDatasetGroupStore::createDatasetGroupTreeItems( const QList<int> &indexes )
527 {
528  QMap<QString, QgsMeshDatasetGroupTreeItem *> mNameToItem;
529 
530  for ( int i = 0; i < indexes.count(); ++i )
531  {
532  int groupIndex = indexes.at( i );
533  const QgsMeshDatasetGroupMetadata meta = datasetGroupMetadata( groupIndex );
534  const QString name = meta.name();
535  const QStringList subdatasets = name.split( '/' );
536 
537  QString displayName = name;
538  QgsMeshDatasetGroupTreeItem *parent = mDatasetGroupTreeRootItem.get();
539 
540  if ( subdatasets.size() == 2 )
541  {
542  auto it = mNameToItem.find( subdatasets[0] );
543  if ( it == mNameToItem.end() )
544  QgsDebugMsg( QStringLiteral( "Unable to find parent group for %1." ).arg( name ) );
545  else
546  {
547  displayName = subdatasets[1];
548  parent = it.value();
549  }
550  }
551  else if ( subdatasets.size() != 1 )
552  QgsDebugMsg( QStringLiteral( "Ignoring too deep child group name %1." ).arg( name ) );
553 
554  QgsMeshDatasetGroupTreeItem *item = new QgsMeshDatasetGroupTreeItem( displayName, name, meta.isVector(), groupIndex );
555  parent->appendChild( item );
556  if ( mNameToItem.contains( name ) )
557  QgsDebugMsg( QStringLiteral( "Group %1 is not unique" ).arg( displayName ) );
558  mNameToItem[name] = item;
559  }
560 }
561 
563 {
564  int groupIndex = mGroups.size();
565  mGroups.push_back( std::unique_ptr<QgsMeshDatasetGroup>( datasetGroup ) );
566 
567  if ( datasetGroup->datasetCount() > 1 )
568  {
569  mTemporalCapabilities->setHasTemporalCapabilities( true );
570  for ( int i = 0; i < datasetGroup->datasetCount(); ++i )
571  mTemporalCapabilities->addDatasetTime( groupIndex, datasetGroup->datasetMetadata( i ).time() );
572  }
573 
574  return mGroups.size() - 1;
575 }
576 
578 {
579  if ( index < datasetGroupCount() )
580  mGroups.erase( mGroups.begin() + index );
581 
582 
584 }
585 
587 {
588  return mTemporalCapabilities->hasTemporalCapabilities();
589 }
590 
592 {
593  return mTemporalCapabilities->datasetTime( index );
594 }
595 
596 QString QgsMeshExtraDatasetStore::description( int groupIndex ) const
597 {
598  if ( groupIndex >= 0 && groupIndex < int( mGroups.size() ) )
599  return mGroups.at( groupIndex )->description();
600  else
601  return QString();
602 }
603 
605 {
606  if ( groupIndex >= 0 && groupIndex < int( mGroups.size() ) )
607  return mGroups[groupIndex].get();
608  else
609  return nullptr;
610 }
611 
612 bool QgsMeshExtraDatasetStore::addDataset( const QString &uri )
613 {
614  Q_UNUSED( uri );
615  return false;
616 }
617 
619 {
620  return QStringList();
621 }
622 
624 {
625  return mGroups.size();
626 }
627 
628 int QgsMeshExtraDatasetStore::datasetCount( int groupIndex ) const
629 {
630  if ( groupIndex >= 0 && groupIndex < datasetGroupCount() )
631  return mGroups.at( groupIndex )->datasetCount();
632  else
633  return 0;
634 }
635 
637 {
638  if ( groupIndex >= 0 && groupIndex < datasetGroupCount() )
639  return mGroups.at( groupIndex )->groupMetadata();
640  else
642 }
643 
645 {
646  int groupIndex = index.group();
647  if ( index.isValid() && groupIndex < datasetGroupCount() )
648  {
649  int datasetIndex = index.dataset();
650  const QgsMeshDatasetGroup *group = mGroups.at( groupIndex ).get();
651  if ( datasetIndex < group->datasetCount() )
652  return group->datasetMetadata( datasetIndex );
653  }
654  return QgsMeshDatasetMetadata();
655 }
656 
658 {
659  int groupIndex = index.group();
660  if ( index.isValid() && groupIndex < datasetGroupCount() )
661  {
662  const QgsMeshDatasetGroup *group = mGroups.at( groupIndex ).get();
663  int datasetIndex = index.dataset();
664  if ( datasetIndex < group->datasetCount() )
665  return group->dataset( datasetIndex )->datasetValue( valueIndex );
666  }
667 
668  return QgsMeshDatasetValue();
669 }
670 
672 {
673  int groupIndex = index.group();
674  if ( index.isValid() && groupIndex < datasetGroupCount() )
675  {
676  const QgsMeshDatasetGroup *group = mGroups.at( groupIndex ).get();
677  int datasetIndex = index.dataset();
678  if ( datasetIndex < group->datasetCount() )
679  return group->dataset( datasetIndex )->datasetValues( group->isScalar(), valueIndex, count );
680  }
681 
682  return QgsMeshDataBlock();
683 }
684 
686 {
687  // Not supported for now
688  Q_UNUSED( index )
689  Q_UNUSED( faceIndex )
690  Q_UNUSED( count )
691  return QgsMesh3dDataBlock();
692 }
693 
695 {
696  int groupIndex = index.group();
697  if ( index.isValid() && groupIndex < datasetGroupCount() )
698  {
699  const QgsMeshDatasetGroup *group = mGroups.at( groupIndex ).get();
700  int datasetIndex = index.dataset();
701  if ( datasetIndex < group->datasetCount() )
702  return group->dataset( datasetIndex )->isActive( faceIndex );
703  }
704 
705  return false;
706 }
707 
709 {
710  int groupIndex = index.group();
711  if ( index.isValid() && groupIndex < datasetGroupCount() )
712  {
713  const QgsMeshDatasetGroup *group = mGroups.at( groupIndex ).get();
714  int datasetIndex = index.dataset();
715  if ( datasetIndex < group->datasetCount() )
716  return group->dataset( datasetIndex )->areFacesActive( faceIndex, count );
717  }
718  return QgsMeshDataBlock();
719 }
720 
721 bool QgsMeshExtraDatasetStore::persistDatasetGroup( const QString &outputFilePath,
722  const QString &outputDriver,
723  const QgsMeshDatasetGroupMetadata &meta,
724  const QVector<QgsMeshDataBlock> &datasetValues,
725  const QVector<QgsMeshDataBlock> &datasetActive,
726  const QVector<double> &times )
727 {
728  Q_UNUSED( outputFilePath )
729  Q_UNUSED( outputDriver )
730  Q_UNUSED( meta )
731  Q_UNUSED( datasetValues )
732  Q_UNUSED( datasetActive )
733  Q_UNUSED( times )
734  return true; // not implemented/supported
735 }
736 
737 bool QgsMeshExtraDatasetStore::persistDatasetGroup( const QString &outputFilePath,
738  const QString &outputDriver,
740  int datasetGroupIndex )
741 {
742  Q_UNUSED( outputFilePath )
743  Q_UNUSED( outputDriver )
744  Q_UNUSED( source )
745  Q_UNUSED( datasetGroupIndex )
746  return true; // not implemented/supported
747 }
748 
749 QDomElement QgsMeshExtraDatasetStore::writeXml( int groupIndex, QDomDocument &doc, const QgsReadWriteContext &context )
750 {
751  if ( groupIndex >= 0 && groupIndex < int( mGroups.size() ) && mGroups[groupIndex] )
752  return mGroups[groupIndex]->writeXml( doc, context );
753  else
754  return QDomElement();
755 }
756 
758 {
759  //update temporal capabilitie
760  mTemporalCapabilities->clear();
761  bool hasTemporal = false;
762  for ( size_t g = 0; g < mGroups.size(); ++g )
763  {
764  const QgsMeshDatasetGroup *group = mGroups[g].get();
765  hasTemporal |= group->datasetCount() > 1;
766  for ( int i = 0; i < group->datasetCount(); ++i )
767  mTemporalCapabilities->addDatasetTime( g, group->datasetMetadata( i ).time() );
768  }
769 
770  mTemporalCapabilities->setHasTemporalCapabilities( hasTemporal );
771 }
QgsMeshDatasetIndex::dataset
int dataset() const
Returns a dataset index within group()
Definition: qgsmeshdataset.cpp:31
qgsmeshlayerutils.h
QgsMeshDatasetSourceInterface::datasetGroupCount
virtual int datasetGroupCount() const =0
Returns number of datasets groups loaded.
QgsMeshExtraDatasetStore::persistDatasetGroup
bool persistDatasetGroup(const QString &outputFilePath, const QString &outputDriver, const QgsMeshDatasetGroupMetadata &meta, const QVector< QgsMeshDataBlock > &datasetValues, const QVector< QgsMeshDataBlock > &datasetActive, const QVector< double > &times) override
Not implemented, always returns true.
Definition: qgsmeshdatasetgroupstore.cpp:721
QgsMeshDatasetGroupStore::setDatasetGroupTreeItem
void setDatasetGroupTreeItem(QgsMeshDatasetGroupTreeItem *rootItem)
Sets the root of the dataset groups tree item, doesn't take onwnershib but clone the root item.
Definition: qgsmeshdatasetgroupstore.cpp:121
qgsmeshdatasetgroupstore.h
QgsMeshDatasetGroupStore::writeXml
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context)
Writes the store's information in a DOM document.
Definition: qgsmeshdatasetgroupstore.cpp:240
QgsMeshDatasetGroupMetadata::DataOnVolumes
@ DataOnVolumes
Data is defined on volumes.
Definition: qgsmeshdataset.h:358
QgsMeshDatasetGroupStore::datasetValue
QgsMeshDatasetValue datasetValue(const QgsMeshDatasetIndex &index, int valueIndex) const
Returns the value of the dataset with global index and valueIndex.
Definition: qgsmeshdatasetgroupstore.cpp:158
QgsMeshDatasetGroupStore::dataset3dValues
QgsMesh3dDataBlock dataset3dValues(const QgsMeshDatasetIndex &index, int faceIndex, int count) const
Returns count 3D values of the dataset with global index and from valueIndex.
Definition: qgsmeshdatasetgroupstore.cpp:176
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsMeshExtraDatasetStore::description
QString description(int groupIndex) const
Returns information related to the dataset group with groupIndex.
Definition: qgsmeshdatasetgroupstore.cpp:596
QgsMeshDatasetSourceInterface::addDataset
virtual bool addDataset(const QString &uri)=0
Associate dataset with the mesh.
QgsMeshDatasetGroupTreeItem::parentItem
QgsMeshDatasetGroupTreeItem * parentItem() const
Returns the parent item, nullptr if it is root item.
Definition: qgsmeshdataset.cpp:593
QgsMeshExtraDatasetStore::extraDatasets
QStringList extraDatasets() const override
Not implemented, always returns empty list.
Definition: qgsmeshdatasetgroupstore.cpp:618
qgsmeshvirtualdatasetgroup.h
QgsMeshDataset::areFacesActive
virtual QgsMeshDataBlock areFacesActive(int faceIndex, int count) const =0
Returns whether faces are active.
QgsMeshDatasetGroup::datasetCount
virtual int datasetCount() const =0
Returns the count of datasets in the group.
QgsMeshDatasetGroupStore::addDatasetGroup
bool addDatasetGroup(QgsMeshDatasetGroup *group)
Adds a extra dataset group, take ownership.
Definition: qgsmeshdatasetgroupstore.cpp:71
QgsMeshDatasetGroupStore::datasetGroupMetadata
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the metadata of the dataset group with global index.
Definition: qgsmeshdatasetgroupstore.cpp:131
QgsMeshDatasetValue
QgsMeshDatasetValue represents single dataset value.
Definition: qgsmeshdataset.h:78
QgsMeshDatasetGroupStore::areFacesActive
QgsMeshDataBlock areFacesActive(const QgsMeshDatasetIndex &index, int faceIndex, int count) const
Returns whether faces are active for particular dataset.
Definition: qgsmeshdatasetgroupstore.cpp:185
QgsMeshDataProviderTemporalCapabilities::datasetTime
qint64 datasetTime(const QgsMeshDatasetIndex &index) const
Returns the relative time in milliseconds of the dataset.
Definition: qgsmeshdataprovidertemporalcapabilities.cpp:159
QgsMeshExtraDatasetStore::datasetValues
QgsMeshDataBlock datasetValues(QgsMeshDatasetIndex index, int valueIndex, int count) const override
Returns N vector/scalar values from the index from the dataset.
Definition: qgsmeshdatasetgroupstore.cpp:671
QgsMeshDatasetGroupTreeItem
Tree item for display of the mesh dataset groups.
Definition: qgsmeshdataset.h:785
QgsMeshDatasetGroupStore::datasetGroupCount
int datasetGroupCount() const
Returns the count of dataset groups.
Definition: qgsmeshdatasetgroupstore.cpp:30
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsMeshDatasetMetadata
QgsMeshDatasetMetadata is a collection of mesh dataset metadata such as whether the data is valid or ...
Definition: qgsmeshdataset.h:476
QgsMeshDatasetMetadata::time
double time() const
Returns the time value for this dataset.
Definition: qgsmeshdataset.cpp:215
QgsMesh3dDataBlock
QgsMesh3dDataBlock is a block of 3d stacked mesh data related N faces defined on base mesh frame.
Definition: qgsmeshdataset.h:245
QgsMeshDatasetGroupTreeItem::clone
QgsMeshDatasetGroupTreeItem * clone() const
Clones the item.
Definition: qgsmeshdataset.cpp:521
qgsapplication.h
QgsMeshExtraDatasetStore::writeXml
QDomElement writeXml(int groupIndex, QDomDocument &doc, const QgsReadWriteContext &context)
Writes the store's information in a DOM document.
Definition: qgsmeshdatasetgroupstore.cpp:749
QgsMeshDataset::datasetValue
virtual QgsMeshDatasetValue datasetValue(int valueIndex) const =0
Returns the value with index valueIndex.
QgsMeshExtraDatasetStore::datasetGroup
QgsMeshDatasetGroup * datasetGroup(int groupIndex) const
Returns a pointer to the dataset group.
Definition: qgsmeshdatasetgroupstore.cpp:604
QgsMeshVirtualDatasetGroup
Represents a dataset group calculated from a formula string.
Definition: qgsmeshvirtualdatasetgroup.h:38
QgsMeshDatasetGroupMetadata::DataOnFaces
@ DataOnFaces
Data is defined on faces.
Definition: qgsmeshdataset.h:356
QgsMeshDatasetGroupMetadata::DataOnVertices
@ DataOnVertices
Data is defined on vertices.
Definition: qgsmeshdataset.h:357
QgsMeshExtraDatasetStore::addDataset
bool addDataset(const QString &uri) override
Not implemented, always returns false.
Definition: qgsmeshdatasetgroupstore.cpp:612
QgsMeshExtraDatasetStore::isFaceActive
bool isFaceActive(QgsMeshDatasetIndex index, int faceIndex) const override
Returns whether the face is active for particular dataset.
Definition: qgsmeshdatasetgroupstore.cpp:694
QgsMeshExtraDatasetStore::areFacesActive
QgsMeshDataBlock areFacesActive(QgsMeshDatasetIndex index, int faceIndex, int count) const override
Returns whether the faces are active for particular dataset.
Definition: qgsmeshdatasetgroupstore.cpp:708
QgsMeshDatasetIndex::group
int group() const
Returns a group index.
Definition: qgsmeshdataset.cpp:26
QgsMeshDatasetGroupStore::extraDatasetGroupCount
int extraDatasetGroupCount() const
Returns the count of extra dataset groups.
Definition: qgsmeshdatasetgroupstore.cpp:35
QgsMeshDatasetGroupTreeItem::removeChild
void removeChild(QgsMeshDatasetGroupTreeItem *item)
Removes a item child if exists.
Definition: qgsmeshdataset.cpp:542
QgsMeshExtraDatasetStore::datasetCount
int datasetCount(int groupIndex) const override
Returns number of datasets loaded in the group.
Definition: qgsmeshdatasetgroupstore.cpp:628
QgsMeshDatasetGroupTreeItem::childCount
int childCount() const
Returns the count of children.
Definition: qgsmeshdataset.cpp:577
QgsMeshDatasetIndex
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Definition: qgsmeshdataset.h:47
QgsMeshDatasetGroupTreeItem::setPersistentDatasetGroup
void setPersistentDatasetGroup(const QString &uri)
Set parameters of the item in accordance with the persistent dataset group with uri.
Definition: qgsmeshdataset.cpp:665
QgsMeshDatasetGroupStore::datasetGroupTreeItem
QgsMeshDatasetGroupTreeItem * datasetGroupTreeItem() const
Returns a pointer to the root of the dataset groups tree item.
Definition: qgsmeshdatasetgroupstore.cpp:116
QgsMeshDatasetGroupStore::datasetGroupIndexes
QList< int > datasetGroupIndexes() const
Returns a list of all group indexes.
Definition: qgsmeshdatasetgroupstore.cpp:25
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:95
QgsMeshDatasetSourceInterface::persistDatasetGroup
virtual Q_DECL_DEPRECATED bool persistDatasetGroup(const QString &path, const QgsMeshDatasetGroupMetadata &meta, const QVector< QgsMeshDataBlock > &datasetValues, const QVector< QgsMeshDataBlock > &datasetActive, const QVector< double > &times)
Creates a new dataset group from a data and persists it into a destination path.
Definition: qgsmeshdataprovider.cpp:86
QgsMeshDataset::datasetValues
virtual QgsMeshDataBlock datasetValues(bool isScalar, int valueIndex, int count) const =0
Returns count values from valueIndex.
QgsMeshDatasetIndex::isValid
bool isValid() const
Returns whether index is valid, ie at least groups is set.
Definition: qgsmeshdataset.cpp:36
QgsMeshDatasetGroupStore::resetDatasetGroupTreeItem
void resetDatasetGroupTreeItem()
Resets to default state the dataset groups tree item.
Definition: qgsmeshdatasetgroupstore.cpp:107
QgsMeshDataProvider::temporalCapabilities
QgsMeshDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
Definition: qgsmeshdataprovider.cpp:29
QgsMeshDataProvider
Base class for providing data for QgsMeshLayer.
Definition: qgsmeshdataprovider.h:398
QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod
MatchingTemporalDatasetMethod
Method for selection of temporal mesh dataset from a range time.
Definition: qgsmeshdataprovidertemporalcapabilities.h:42
QgsMeshDataSourceInterface::edgeCount
virtual int edgeCount() const =0
Returns number of edges in the native mesh.
QgsMeshExtraDatasetStore::datasetRelativeTime
quint64 datasetRelativeTime(QgsMeshDatasetIndex index)
Returns the relative times of the dataset index with index, returned value in milliseconds.
Definition: qgsmeshdatasetgroupstore.cpp:591
QgsMeshExtraDatasetStore::datasetGroupCount
int datasetGroupCount() const override
Returns number of datasets groups loaded.
Definition: qgsmeshdatasetgroupstore.cpp:623
QgsMeshDatasetGroupStore::datasetMetadata
QgsMeshDatasetMetadata datasetMetadata(const QgsMeshDatasetIndex &index) const
Returns the metadata of the dataset with global index.
Definition: qgsmeshdatasetgroupstore.cpp:149
QgsMeshDataSourceInterface::vertexCount
virtual int vertexCount() const =0
Returns number of vertices in the native mesh.
QgsMeshDatasetGroupMetadata::DataOnEdges
@ DataOnEdges
Data is defined on edges.
Definition: qgsmeshdataset.h:359
QgsMeshDatasetGroupTreeItem::setDatasetGroup
void setDatasetGroup(QgsMeshDatasetGroup *datasetGroup)
Set parameters of the item in accordance with the dataset group.
Definition: qgsmeshdataset.cpp:649
QgsMeshDatasetSourceInterface
Interface for mesh datasets and dataset groups.
Definition: qgsmeshdataprovider.h:189
QgsMeshDatasetGroupMetadata::name
QString name() const
Returns name of the dataset group.
Definition: qgsmeshdataset.cpp:166
QgsMeshDatasetGroup::dataset
virtual QgsMeshDataset * dataset(int index) const =0
Returns the dataset with index.
QgsMeshDatasetGroup::isScalar
bool isScalar() const
Returns whether the group contain scalar values.
Definition: qgsmeshdataset.cpp:1049
QgsMeshDatasetGroup
Abstract class that represents a dataset group.
Definition: qgsmeshdataset.h:576
QgsMeshDatasetGroup::datasetMetadata
virtual QgsMeshDatasetMetadata datasetMetadata(int datasetIndex) const =0
Returns the metadata of the dataset with index datasetIndex.
qgsmeshlayer.h
QgsMeshExtraDatasetStore::datasetGroupMetadata
QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const override
Returns dataset group metadata.
Definition: qgsmeshdatasetgroupstore.cpp:636
QgsMeshExtraDatasetStore::hasTemporalCapabilities
bool hasTemporalCapabilities() const
Returns whether if the dataset groups have temporal capabilities (a least one dataset group with more...
Definition: qgsmeshdatasetgroupstore.cpp:586
QgsMeshDatasetGroupStore::datasetCount
int datasetCount(int groupIndex) const
Returns the total count of dataset group in the store.
Definition: qgsmeshdatasetgroupstore.cpp:140
QgsMeshDatasetGroupStore::hasTemporalCapabilities
bool hasTemporalCapabilities() const
Returns whether at lea&st one of stored dataset group is temporal.
Definition: qgsmeshdatasetgroupstore.cpp:234
QgsMeshDataSourceInterface::faceCount
virtual int faceCount() const =0
Returns number of faces in the native mesh.
QgsMeshDatasetGroupMetadata
QgsMeshDatasetGroupMetadata is a collection of dataset group metadata such as whether the data is vec...
Definition: qgsmeshdataset.h:350
QgsMeshDatasetGroupStore::isFaceActive
bool isFaceActive(const QgsMeshDatasetIndex &index, int faceIndex) const
Returns whether face is active for particular dataset.
Definition: qgsmeshdatasetgroupstore.cpp:194
QgsMeshExtraDatasetStore::datasetValue
QgsMeshDatasetValue datasetValue(QgsMeshDatasetIndex index, int valueIndex) const override
Returns vector/scalar value associated with the index from the dataset To read multiple continuous va...
Definition: qgsmeshdatasetgroupstore.cpp:657
QgsMeshExtraDatasetStore
Class that can be used to store and access extra dataset group, like memory dataset (temporary) Deriv...
Definition: qgsmeshdatasetgroupstore.h:37
QgsMeshDatasetGroupStore::QgsMeshDatasetGroupStore
QgsMeshDatasetGroupStore(QgsMeshLayer *layer)
Constructor.
Definition: qgsmeshdatasetgroupstore.cpp:40
QgsMeshDatasetGroupTreeItem::appendChild
void appendChild(QgsMeshDatasetGroupTreeItem *item)
Appends a item child.
Definition: qgsmeshdataset.cpp:535
QgsMeshDatasetGroup::dataType
QgsMeshDatasetGroupMetadata::DataType dataType() const
Returns the data type of the dataset group.
Definition: qgsmeshdataset.cpp:1029
QgsMeshExtraDatasetStore::datasetMetadata
QgsMeshDatasetMetadata datasetMetadata(QgsMeshDatasetIndex index) const override
Returns dataset metadata.
Definition: qgsmeshdatasetgroupstore.cpp:644
QgsMeshDataProvider::datasetGroupsAdded
void datasetGroupsAdded(int count)
Emitted when some new dataset groups have been added.
QgsMeshDatasetGroupStore::datasetGroupsAdded
void datasetGroupsAdded(QList< int > indexes)
Emitted after dataset groups are added.
QgsMeshDataBlock
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e....
Definition: qgsmeshdataset.h:136
QgsMeshDatasetGroupStore::readXml
void readXml(const QDomElement &storeElem, const QgsReadWriteContext &context)
Reads the store's information from a DOM document.
Definition: qgsmeshdatasetgroupstore.cpp:277
QgsMeshDatasetGroupTreeItem::datasetGroupIndex
int datasetGroupIndex() const
Definition: qgsmeshdataset.cpp:619
QgsMeshExtraDatasetStore::addDatasetGroup
int addDatasetGroup(QgsMeshDatasetGroup *datasetGroup)
Adds a dataset group, returns the index of the added dataset group.
Definition: qgsmeshdatasetgroupstore.cpp:562
QgsMeshDatasetGroupStore::saveDatasetGroup
bool saveDatasetGroup(QString filePath, int groupIndex, QString driver)
Saves on a file with filePath the dataset groups index with groupIndex with the specified driver.
Definition: qgsmeshdatasetgroupstore.cpp:327
QgsMeshDatasetGroupStore::setPersistentProvider
void setPersistentProvider(QgsMeshDataProvider *provider)
Sets the persistent mesh data provider.
Definition: qgsmeshdatasetgroupstore.cpp:46
QgsMeshDatasetGroupStore::addPersistentDatasets
bool addPersistentDatasets(const QString &path)
Adds persistent datasets from a file with path.
Definition: qgsmeshdatasetgroupstore.cpp:64
QgsMeshDatasetGroupStore::datasetValues
QgsMeshDataBlock datasetValues(const QgsMeshDatasetIndex &index, int valueIndex, int count) const
Returns count values of the dataset with global index and from valueIndex.
Definition: qgsmeshdatasetgroupstore.cpp:167
QgsMeshDatasetGroupStore::datasetIndexAtTime
QgsMeshDatasetIndex datasetIndexAtTime(qint64 time, int groupIndex, QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod method) const
Returns the global dataset index of the dataset int the dataset group with groupIndex,...
Definition: qgsmeshdatasetgroupstore.cpp:203
QgsMeshDatasetGroupMetadata::uri
QString uri() const
Returns the uri of the source.
Definition: qgsmeshdataset.cpp:196
QgsDataProviderTemporalCapabilities::hasTemporalCapabilities
bool hasTemporalCapabilities() const
Returns true if the provider has temporal capabilities available.
Definition: qgsdataprovidertemporalcapabilities.h:74
QgsMeshDatasetGroupMetadata::isVector
bool isVector() const
Returns whether dataset group has vector data.
Definition: qgsmeshdataset.cpp:151
QgsMeshDatasetGroupTreeItem::child
QgsMeshDatasetGroupTreeItem * child(int row) const
Returns a child.
Definition: qgsmeshdataset.cpp:547
QgsMeshDataset::isActive
virtual bool isActive(int faceIndex) const =0
Returns whether the face is active.
QgsMeshDatasetGroup::checkValueCountPerDataset
bool checkValueCountPerDataset(int count) const
Returns whether all the datasets contain count values.
Definition: qgsmeshdataset.cpp:989
QgsMeshDatasetSourceInterface::datasetGroupMetadata
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.
QgsMeshExtraDatasetStore::removeDatasetGroup
void removeDatasetGroup(int index)
Removes the dataset group with the local index.
Definition: qgsmeshdatasetgroupstore.cpp:577
QgsMeshDatasetGroupStore::datasetRelativeTime
qint64 datasetRelativeTime(const QgsMeshDatasetIndex &index) const
Returns the relative time of the dataset from the persistent provider reference time.
Definition: qgsmeshdatasetgroupstore.cpp:217
QgsMeshExtraDatasetStore::updateTemporalCapabilities
void updateTemporalCapabilities()
Updates the temporal capabilities.
Definition: qgsmeshdatasetgroupstore.cpp:757
QgsMeshDatasetSourceInterface::mTemporalCapabilities
std::unique_ptr< QgsMeshDataProviderTemporalCapabilities > mTemporalCapabilities
Definition: qgsmeshdataprovider.h:383
QgsMeshDataProviderTemporalCapabilities::referenceTime
QDateTime referenceTime() const
Returns the reference time.
Definition: qgsmeshdataprovidertemporalcapabilities.cpp:104
QgsMeshExtraDatasetStore::dataset3dValues
QgsMesh3dDataBlock dataset3dValues(QgsMeshDatasetIndex index, int faceIndex, int count) const override
Returns N vector/scalar values from the face index from the dataset for 3d stacked meshes.
Definition: qgsmeshdatasetgroupstore.cpp:685
INVALID_MESHLAYER_TIME
#define INVALID_MESHLAYER_TIME
Definition: qgsmeshdataprovidertemporalcapabilities.h:25