Ejemplo n.º 1
0
const TrackManager* OnboardComputer::getTrackManagerByName(const char* const name) const
{
   const TrackManager* p = 0;
   const Basic::Pair* pair = findByName(name);
   if (pair != 0) {
      p = dynamic_cast<const TrackManager*>( pair->object() );
   }
   return p;
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
// getTrackManagerByName() -- return a track manager by name
//------------------------------------------------------------------------------
TrackManager* OnboardComputer::getTrackManagerByName(const char* const name)
{
   TrackManager* p = nullptr;
   base::Pair* pair = findByName(name);
   if (pair != nullptr) {
      p = dynamic_cast<TrackManager*>( pair->object() );
   }
   return p;
}
Ejemplo n.º 3
0
// Send an event message to component 'id'
bool Component::send(const char* const id, const int event)
{
    bool val {};
    Pair* p = findByName(id);
    if (p != nullptr) {
        const auto g = static_cast<Component*>(p->object());
        val = g->event(event);
    }
    return val;
}
Ejemplo n.º 4
0
    virtual ActivePet* load(std::wstring petname) {
        ActivePet* r = findByName(petname);
        if (!r) {
            r = openPet(petname, m_password);
            if (r) {
                m_pets.push_back(r);
            }
        }
	    return r;
    }
void TCompBoneTracker::onGroupCreated(const TMsgEntityGroupCreated& msg) {
    h_entity = findByName(*msg.handles, entity_name);
    CEntity* e = h_entity;
    if (!e)
        return;
    TCompSkeleton* skel = e->get<TCompSkeleton>();
    if (!skel)
        return;
    bone_id = skel->model->getSkeleton()->getCoreSkeleton()->getCoreBoneId(bone_name);
}
Ejemplo n.º 6
0
// Send an event message to component 'id'
bool Component::send(const char* const id, const int event)
{
    bool val = false;
    Pair* p = findByName(id);
    if (p != 0) {
        Component* g = (Component*) p->object();
        val = g->event(event);
    }
    return val;
}
Ejemplo n.º 7
0
	bool Rename( const FSString& oldName, const FSString& newName )
	{
		FSArchNode* n = findByName( newName );

		if ( !n )
		{
			return false;
		}

		n->name = newName;
		return true;
	}
Ejemplo n.º 8
0
FSArchNode* FSArchNode::Add( const FSArchNode& fsArchNode )
{
	if ( findByName( fsArchNode.name ) )
	{
		return nullptr;
	}

	content.push_back( fsArchNode );

	FSArchNode* Dir = &content.back();
	Dir->parentDir = this;
	return Dir;
}
Ejemplo n.º 9
0
//------------------------------------------------------------------------------
// select() -- select one of our components, using String or Number
//------------------------------------------------------------------------------
bool Component::select(const String* const name)
{
    bool ok {true};
    selected = nullptr;
    setSelectionName(nullptr);
    if (name != nullptr) {
        setSelectionName(name);
        Pair* p = findByName(*name);
        if (p != nullptr) selected = static_cast<Component*>(p->object());
        else {
            std::cerr << "Component::select: name not found!"  << std::endl;
            ok = false;
        }
    }
    return ok;
}
Ejemplo n.º 10
0
//------------------------------------------------------------------------------
// select() -- select one of our components, using String or Number
//------------------------------------------------------------------------------
bool Component::select(const String* const name)
{
    bool ok = true;
    selected = 0;
    setSelectionName(0);
    if (name != 0) {
        setSelectionName(name);
        Pair* p = findByName(*name);
        if (p != 0) selected = (Component*) p->object();
        else {
            std::cerr << "Component::select: name not found!"  << std::endl; 
            ok = false;
        }
    }
    return ok;
}
Ejemplo n.º 11
0
bool SplashScreenState::keyPressed(const OIS::KeyEvent &keyEventRef)
{
	if (OgreFramework::getSingletonPtr()->m_pKeyboard->isKeyDown(OIS::KC_ESCAPE))
	{
		m_bQuit = true;
		return true;
	}
	if (OgreFramework::getSingletonPtr()->m_pKeyboard->isKeyDown(OIS::KC_RETURN) ||
		OgreFramework::getSingletonPtr()->m_pKeyboard->isKeyDown(OIS::KC_SPACE))
	{
		changeAppState(findByName("MenuState"));
	}

	OgreFramework::getSingletonPtr()->keyPressed(keyEventRef);
	return true;
}
Ejemplo n.º 12
0
bool CDropTarget::EnterViewMsg(CEnterViewMsg *msg) {
	if (!_itemName.empty()) {
		CGameObject *obj = dynamic_cast<CGameObject *>(findByName(_itemName));
		if (!obj) {
			loadFrame(_dragFrame);
			_cursorId = _dragCursorId;
		} else if (_clipName.empty()) {
			loadFrame(_dropFrame);
		} else {
			playClip(_clipName, _clipFlags);
		}

		_cursorId = _dropCursorId;
	}

	return true;
}
Ejemplo n.º 13
0
void Widget::serverDownloadStart()
{
   QTreeWidgetItem * item = ftpFiles->invisibleRootItem();
   QTreeWidgetItem * header = ftpFiles->headerItem();
   QStringList lst;
   Computer * comp;

   for(int i = 1; i < ftpFiles->columnCount(); i++)
   {
      lst = rebuildPath(item, "", i);
      comp = findByName(header->text(i));
      foreach(QString str, lst)
      {
          comp->getSocket()->write(QByteArray("ADFL::" + str.toAscii()));
      }
      comp->getSocket()->write(QByteArray("DNLD::"));
    }
Ejemplo n.º 14
0
/**
 * @brief Translate color value to terrain type to random weather code
 * @param[in] tdef The terrain definition to add
 */
bool TerrainDefs::add(const TerrainDef* tdef) {
	/* check for duplicate color code */
	if (findByColor(tdef->rgbRed, tdef->rgbGreen, tdef->rgbBlue))
		return false;

	/* check for duplicate name */
	if (findByName(tdef->terrainName))
		return false;

	for (int i = 0; i < MAX_TERRAINDEFS - 1; i++) {
		if (!terrainDefTable[i]) {
			terrainDefTable[i] = tdef;
			terrainDefTable[i + 1] = nullptr;
			return true;
		}
	}
	return false;
}
Ejemplo n.º 15
0
 bool ReplSetImpl::shouldChangeSyncTarget(const HostAndPort& currentTarget) {
     lock lk(this);
     OpTime targetOpTime = findByName(currentTarget.toString())->hbinfo().opTime;
     for (Member *m = _members.head(); m; m = m->next()) {
         if (m->syncable() &&
             targetOpTime.getSecs()+maxSyncSourceLagSecs < m->hbinfo().opTime.getSecs()) {
             log() << "changing sync target because current sync target's most recent OpTime is "
                   << targetOpTime.toStringPretty() << " which is more than "
                   << maxSyncSourceLagSecs << " seconds behind member " << m->fullName()
                   << " whose most recent OpTime is " << m->hbinfo().opTime.getSecs();
             return true;
         }
     }
     if (gotForceSync()) {
         return true;
     }
     return false;
 }
Ejemplo n.º 16
0
skelPoseAction * skelPoseActionList::addAction(string _name, int _id) {
	skelPoseAction * result;
	int i = findById(_id);
	if(i > -1) {
		result = actions[i];
	} else {
		i = findByName(_name);
		if(i > -1) {
			result = actions[i];
		} else {
			result = new skelPoseAction();
			result->name = _name;
			result->id = _id;
			actions.push_back(result);
		}
	}
		 
	return result;
}
Ejemplo n.º 17
0
 /**
  * @brief Merge the contents of another Kernels object
  *
  * This method mergest the contents of another Kernels object into this one.
  * Kernels that exist in both instances of the object are handled special.
  * The status of this object's version of the file is updated to reflect
  * conditions of the other objects kernels.
  *
  * When the file does not exist in this object, the kernel file structure is
  * copied from the other Kernels object, its managed status is set to false
  * (since it pre-exists in another object that must relinquish its management
  * of it) and is added to this objects kernel list.
  *
  * When the file does exist in this object, its load status is checked in the
  * other Kernels object.  If it is loaded according to the other object, it is
  * marked as loaded in this object and its managed state is set to unmanaged
  * (since it contained in another object, no assumptions can be made as to
  * whom and how it came about to be loaded.
  *
  * The following code fragment demonstrates how to ensure only one Kernels
  * object retains complete control of the merged set of kernels:
  *
  * @code
  *
  * Kernels master, other;
  *
  * //  ...
  *
  *
  * //  Both objects are assumed to contain kenels and some state.
  * master.Merge(other);
  * other.UnManage();
  * master.Manage();
  * master.UpdateLoadStatus();
  * @endcode
  *
  * The UpdateLoadStatus() ensures the state of the managed kernel list in
  * master is completely up to date.
  *
  * @param other Other Kenels object containing a separate list of NAIF
  *              kernels that will be merged with the contents of this object.
  *
  * @return int Number of kernels added to this object.  It does not include
  *             the count of kernels that are common to both and may have had
  *             its status modified.
  */
 int Kernels::Merge(const Kernels &other) {
   int nAdded(0);
   for (unsigned int i = 0 ; i < other._kernels.size() ; i++) {
     KernelFile *kernel = findByName(other._kernels[i].fullpath);
     if (kernel == 0) {
       KernelFile kfile = other._kernels[i];
       kfile.managed = false;
       _kernels.push_back(kfile);
       nAdded++;
     }
     else {
       if (other._kernels[i].loaded) {
         kernel->loaded = true;
         kernel->managed = false;
       }
     }
   }
   return (nAdded);
 }
Ejemplo n.º 18
0
FSArchNode* FSArchNode::findByFsPath( FSPath& fsPath, int fsPathLevel )
{
	FSString* curName = fsPath.GetItem( fsPathLevel );

	if ( parentDir == nullptr
	     && fsPathLevel == fsPath.Count() - 1
	     && ( curName == nullptr || curName->GetUnicode() == 0 || curName->GetUnicode()[0] == 0 ) )
	{
		// request to find root node, and we are root
		return this;
	}

	if ( name.Cmp( *curName ) == 0 )
	{
		if ( fsPath.Count() <= fsPathLevel )
		{
			// exact match
			return this;
		}

		FSString* childName = fsPath.GetItem( fsPathLevel + 1 );
		FSArchNode* n = findByName( *childName );

		if ( n == nullptr )
		{
			return nullptr;
		}

		if ( fsPath.Count() <= fsPathLevel + 2 )
		{
			// no further recursion
			return n;
		}

		if ( n->IsDir() )
		{
			// recurse into subdir
			return n->findByFsPath( fsPath, fsPathLevel + 1 );
		}
	}

	return nullptr;
}
Ejemplo n.º 19
0
//! solve a node, finding it by name
//! @param[in] nameNode    name of the node
void AOgraph::solveByName(string nameNode)
{
    AOnode* solved = findByName(nameNode);
    bool result = solved->setSolved();
    updateNodeFeasibility();
    printGraphInfo();
    
    // report that the graph has been solved if the solved node is the head node
    if (head->nSolved == true)
    {
        cout<<"[REPORT] The graph is solved (head node solved)." <<endl;
        return;
    }
    
    // update the path information (cost) of all paths
    if (result == true)
        updatePaths(*solved);
    cout<<endl <<"Updated paths: " <<endl;
    for(int i=0; i< (int)pUpdate.size(); i++)
        cout<<"Path index: " <<pIndices[i] <<" - Benefit: " <<pUpdate[i] <<endl;
}
Ejemplo n.º 20
0
bool CDropTarget::DropZoneLostObjectMsg(CDropZoneLostObjectMsg *msg) {
	if (!_itemName.empty()) {
		CGameObject *obj = dynamic_cast<CGameObject *>(findByName(_itemName));
		if (obj) {
			if (msg->_object) {
				obj->detach();
				obj->addUnder(msg->_object);
			} else if (dynamic_cast<CCarry *>(obj)) {
				obj->petAddToInventory();
			}

			setVisible(true);
			CDropZoneLostObjectMsg lostMsg(this);
			lostMsg.execute(obj);
		}

		loadFrame(_dragFrame);
		_cursorId = _dragCursorId;
	}

	return true;
}
Ejemplo n.º 21
0
//------------------------------------------------------------------------------
// updateData() - update non time-critical stuff here
//------------------------------------------------------------------------------
void LandingGear::updateData(const double dt)
{
    BaseClass::updateData(dt);

    // this will store our last value, so we know which way we are going
    double lastPos = gearPos;
    gearPos = getInstValue();

    if (gearPos == gearUV) {
        gearState = 0;
        inTransit = false;
    }
    else if (gearPos == gearDV) {
        gearState = 1;
        inTransit = false;
    }
    // if we aren't equal to either, we are in transit
    else {
        inTransit = true;
        // we are going towards the gear up value
        if (gearPos < lastPos) gearState = 0;
        // we are going towards the down value
        else if (gearPos > lastPos) gearState = 1;
        // if we are equal, we do nothing
    }

    // now send our select down based on our transition flag and gear pos
    int x = 0;
    if (gearState == 0 && !inTransit) x = 1;
    else if (gearState == 0 && inTransit) x = 2;
    else if (gearState == 1 && inTransit) x = 3;
    else if (gearState == 1 && !inTransit) x = 4;

    send("gearpos", SELECT, x, gearSelSD);

    // determine if we have a rotary
    base::Pair* pair = (base::Pair*)findByName("gearpos");
    if (pair != nullptr) haveRotary = true;
}
Ejemplo n.º 22
0
DomainPtr DomainCollectionBase::getDomain(const wxString& name)
{
    DomainPtr domain = findByName(name);
    if (!domain)
    {
        SubjectLocker lock(this);

        DatabasePtr db = getDatabase();
        MetadataLoader* loader = db->getMetadataLoader();
        MetadataLoaderTransaction tr(loader);
        wxMBConv* converter = db->getCharsetConverter();

        IBPP::Statement& st1 = loader->getStatement(
            Domain::getLoadStatement(false));
        st1->Set(1, wx2std(name, converter));
        st1->Execute();
        if (st1->Fetch())
        {
            domain = insert(name);
            domain->loadProperties(st1, converter);
        }
    }
    return domain;
}
Ejemplo n.º 23
0
void SplashScreenState::buttonHit(OgreBites::Button *button)
{
	if (button->getName() == "SplashBtn")
		changeAppState(findByName("GameState"));
}
Ejemplo n.º 24
0
//Reimplement draw function so that we have control over the order of
//elements, and we can add object labels
//
//The order in which components are drawn naturally determines the
//z-ordering (the layering) of the components.  Objects which
//should appear "behind" others should be drawn first.
void SkyMapComposite::draw( SkyPainter *skyp )
{
    Q_UNUSED(skyp)
#ifndef KSTARS_LITE
    SkyMap *map = SkyMap::Instance();
    KStarsData *data = KStarsData::Instance();

    // We delay one draw cycle before re-indexing
    // we MUST ensure CLines do not get re-indexed while we use DRAW_BUF
    // so we do it here.
    m_CLines->reindex( &m_reindexNum );
    // This queues re-indexing for the next draw cycle
    m_reindexNum = KSNumbers( data->updateNum()->julianDay() );

    // This ensures that the JIT updates are synchronized for the entire draw
    // cycle so the sky moves as a single sheet.  May not be needed.
    data->syncUpdateIDs();

    // prepare the aperture
    // FIXME_FOV: We may want to rejigger this to allow
    // wide-angle views --hdevalence
    float radius = map->projector()->fov();
    if ( radius > 180.0 )
        radius = 180.0;


    if ( m_skyMesh->inDraw() ) {
        printf("Warning: aborting concurrent SkyMapComposite::draw()\n");
        return;
    }

    m_skyMesh->inDraw( true );
    SkyPoint* focus = map->focus();
    m_skyMesh->aperture( focus, radius + 1.0, DRAW_BUF ); // divide by 2 for testing

    // create the no-precess aperture if needed
    if ( Options::showEquatorialGrid() || Options::showHorizontalGrid() || Options::showCBounds() || Options::showEquator() ) {
        m_skyMesh->index( focus, radius + 1.0, NO_PRECESS_BUF );
    }

    // clear marks from old labels and prep fonts
    m_skyLabeler->reset( map );
    m_skyLabeler->useStdFont();

    // info boxes have highest label priority
    // FIXME: REGRESSION. Labeler now know nothing about infoboxes
    // map->infoBoxes()->reserveBoxes( psky );

    // JM 2016-12-01: Why is this done this way?!! It's too inefficient
    if( KStars::Instance() )
    {
        auto& obsList = KStarsData::Instance()->observingList()->sessionList();
        if( Options::obsListText() )
            foreach( QSharedPointer<SkyObject> obj_clone, obsList ) {
                // Find the "original" obj
                SkyObject *o = findByName( obj_clone->name() ); // FIXME: This is sloww.... and can also fail!!!
                if ( !o )
                    continue;
                SkyLabeler::AddLabel( o, SkyLabeler::RUDE_LABEL );
            }
    }
Ejemplo n.º 25
0
bool SymbolTable::isDefined(StringRef sym) {
  if (const Atom *atom = findByName(sym))
    return atom->definition() != Atom::definitionUndefined;
  return false;
}
Ejemplo n.º 26
0
bool SymbolTable::addByName(const Atom &newAtom) {
  StringRef name = newAtom.name();
  assert(!name.empty());
  const Atom *existing = findByName(name);
  if (existing == nullptr) {
    // Name is not in symbol table yet, add it associate with this atom.
    _nameTable[name] = &newAtom;
    return true;
  }

  // Do nothing if the same object is added more than once.
  if (existing == &newAtom)
    return false;

  // Name is already in symbol table and associated with another atom.
  bool useNew = true;
  switch (collide(existing->definition(), newAtom.definition())) {
  case NCR_First:
    useNew = false;
    break;
  case NCR_Second:
    useNew = true;
    break;
  case NCR_DupDef:
    assert(existing->definition() == Atom::definitionRegular);
    assert(newAtom.definition() == Atom::definitionRegular);
    switch (mergeSelect(((DefinedAtom*)existing)->merge(),
                        ((DefinedAtom*)&newAtom)->merge())) {
    case MCR_First:
      useNew = false;
      break;
    case MCR_Second:
      useNew = true;
      break;
    case MCR_Largest: {
      uint64_t existingSize = sectionSize((DefinedAtom*)existing);
      uint64_t newSize = sectionSize((DefinedAtom*)&newAtom);
      useNew = (newSize >= existingSize);
      break;
    }
    case MCR_SameSize: {
      uint64_t existingSize = sectionSize((DefinedAtom*)existing);
      uint64_t newSize = sectionSize((DefinedAtom*)&newAtom);
      if (existingSize == newSize) {
        useNew = true;
        break;
      }
      llvm::errs() << "Size mismatch: "
                   << existing->name() << " (" << existingSize << ") "
                   << newAtom.name() << " (" << newSize << ")\n";
      // fallthrough
    }
    case MCR_Error:
      if (!_context.getAllowDuplicates()) {
        llvm::errs() << "Duplicate symbols: "
                     << existing->name()
                     << ":"
                     << existing->file().path()
                     << " and "
                     << newAtom.name()
                     << ":"
                     << newAtom.file().path()
                     << "\n";
        llvm::report_fatal_error("duplicate symbol error");
      }
      useNew = false;
      break;
    }
    break;
  case NCR_DupUndef: {
    const UndefinedAtom* existingUndef = cast<UndefinedAtom>(existing);
    const UndefinedAtom* newUndef = cast<UndefinedAtom>(&newAtom);

    bool sameCanBeNull = (existingUndef->canBeNull() == newUndef->canBeNull());
    if (!sameCanBeNull &&
        _context.warnIfCoalesableAtomsHaveDifferentCanBeNull()) {
      llvm::errs() << "lld warning: undefined symbol "
                   << existingUndef->name()
                   << " has different weakness in "
                   << existingUndef->file().path()
                   << " and in " << newUndef->file().path() << "\n";
    }

    const UndefinedAtom *existingFallback = existingUndef->fallback();
    const UndefinedAtom *newFallback = newUndef->fallback();
    bool hasDifferentFallback =
        (existingFallback && newFallback &&
         existingFallback->name() != newFallback->name());
    if (hasDifferentFallback) {
      llvm::errs() << "lld warning: undefined symbol "
                   << existingUndef->name() << " has different fallback: "
                   << existingFallback->name() << " in "
                   << existingUndef->file().path() << " and "
                   << newFallback->name() << " in "
                   << newUndef->file().path() << "\n";
    }

    bool hasNewFallback = newUndef->fallback();
    if (sameCanBeNull)
      useNew = hasNewFallback;
    else
      useNew = (newUndef->canBeNull() < existingUndef->canBeNull());
    break;
  }
  case NCR_DupShLib: {
    const SharedLibraryAtom *curShLib = cast<SharedLibraryAtom>(existing);
    const SharedLibraryAtom *newShLib = cast<SharedLibraryAtom>(&newAtom);
    bool sameNullness =
        (curShLib->canBeNullAtRuntime() == newShLib->canBeNullAtRuntime());
    bool sameName = curShLib->loadName().equals(newShLib->loadName());
    if (sameName && !sameNullness &&
        _context.warnIfCoalesableAtomsHaveDifferentCanBeNull()) {
      // FIXME: need diagonstics interface for writing warning messages
      llvm::errs() << "lld warning: shared library symbol "
                   << curShLib->name() << " has different weakness in "
                   << curShLib->file().path() << " and in "
                   << newShLib->file().path();
    }
    if (!sameName && _context.warnIfCoalesableAtomsHaveDifferentLoadName()) {
      // FIXME: need diagonstics interface for writing warning messages
      llvm::errs() << "lld warning: shared library symbol "
                   << curShLib->name() << " has different load path in "
                   << curShLib->file().path() << " and in "
                   << newShLib->file().path();
    }
    useNew = false;
    break;
  }
  case NCR_Error:
    llvm::errs() << "SymbolTable: error while merging " << name << "\n";
    llvm::report_fatal_error("duplicate symbol error");
    break;
  }

  if (useNew) {
    // Update name table to use new atom.
    _nameTable[name] = &newAtom;
    // Add existing atom to replacement table.
    _replacedAtoms[existing] = &newAtom;
  } else {
    // New atom is not being used.  Add it to replacement table.
    _replacedAtoms[&newAtom] = existing;
  }
  return false;
}
Ejemplo n.º 27
0
// Given a notebook's name as a QString, we return the lid
qint32 LinkedNotebookTable::findByName(QString &name) {
    string n = name.toStdString();
    return findByName(n);
}
Ejemplo n.º 28
0
void SupernovaeComponent::loadData()
{
    QString serialNo, hostGalaxy, date, type, offset, SNPosition, discoverers ;
    dms ra, dec;
    float magnitude;
    qDebug()<<"Loading Supernovae data";
    //m_ObjectList.clear();
    latest.clear();
    objectNames(SkyObject::SUPERNOVA).clear();
    
    KStarsData *m_data = KStarsData::Instance(); // to convert equatorial coordinate to horizontal

    //SN     ,Host Galaxy     ,Date       , R.A.  , Decl.,   Offset  ,Mag.,  Disc. Ref.     ,      SN Position      ,  Posn. Ref.      ,Typ,  SN     ,Discoverer(s)
    QList< QPair<QString,KSParser::DataTypes> > sequence;
    sequence.append(qMakePair(QString("serialNo"),      KSParser::D_QSTRING));
    sequence.append(qMakePair(QString("hostGalaxy"),    KSParser::D_QSTRING));
    sequence.append(qMakePair(QString("date"),          KSParser::D_QSTRING));
    sequence.append(qMakePair(QString("ra"),            KSParser::D_QSTRING));
    sequence.append(qMakePair(QString("dec"),           KSParser::D_QSTRING));
    sequence.append(qMakePair(QString("offset"),        KSParser::D_QSTRING));
    sequence.append(qMakePair(QString("magnitude"),     KSParser::D_FLOAT));
    sequence.append(qMakePair(QString("ignore1"),       KSParser::D_SKIP));
    sequence.append(qMakePair(QString("SNPosition"),    KSParser::D_QSTRING));
    sequence.append(qMakePair(QString("ignore2"),       KSParser::D_SKIP));
    sequence.append(qMakePair(QString("type"),          KSParser::D_QSTRING));
    sequence.append(qMakePair(QString("ignore3"),       KSParser::D_SKIP));
    sequence.append(qMakePair(QString("discoverers"),   KSParser::D_QSTRING));

    QString file_name = QStandardPaths::locate(QStandardPaths::DataLocation,
                                               QString("supernovae.dat"));
    KSParser snParser(file_name, '#', sequence);

    QHash<QString, QVariant> row_content;
    while (snParser.HasNextRow()){
        Supernova *sup=0;
        row_content = snParser.ReadNextRow();

        if(row_content["serialNo"].toString() == "Null")
            continue;

        serialNo    = row_content["serialNo"].toString().trimmed();
        hostGalaxy  = row_content["hostGalaxy"].toString();
        date        = row_content["date"].toString();
        ra          = dms(row_content["ra"].toString(), false);
        dec         = dms(row_content["dec"].toString());
        offset      = row_content["offset"].toString();
        magnitude   = row_content["magnitude"].toFloat();
        SNPosition  = row_content["SNPosition"].toString();
        type        = row_content["type"].toString();
        discoverers = row_content["discoverers"].toString();

        if (magnitude == KSParser::EBROKEN_FLOAT)
            magnitude = 99.9;

        sup=new Supernova(ra, dec, date, magnitude, serialNo, type, hostGalaxy, offset, discoverers);
        sup->EquatorialToHorizontal(m_data->lst(),m_data->geo()->lat());
        if (!m_ObjectList.empty())
        {
            if ( findByName(sup->name() ) == 0 )
            {
                //qDebug()<<"List of supernovae not empty. Found new supernova";
                m_ObjectList.append(sup);
                latest.append(sup);
            }/*
            else
                m_ObjectList.append(sup);*/
        }
        else             //if the list is empty
        {
            m_ObjectList.append(sup);
            latest.append(sup);
            //notifyNewSupernovae();
        }

        objectNames(SkyObject::SUPERNOVA).append(sup->name());
    }
    //notifyNewSupernovae();
}
Ejemplo n.º 29
0
int GModel::readMED(const std::string &name)
{
  med_idt fid = MEDouvrir((char*)name.c_str(), MED_LECTURE);
  if(fid < 0) {
    Msg::Error("Unable to open file '%s'", name.c_str());
    return 0;
  }

  med_int v[3], vf[3];
  MEDversionDonner(&v[0], &v[1], &v[2]);
  MEDversionLire(fid, &vf[0], &vf[1], &vf[2]);
  Msg::Info("Reading MED file V%d.%d.%d using MED library V%d.%d.%d",
            vf[0], vf[1], vf[2], v[0], v[1], v[2]);
  if(vf[0] < 2 || (vf[0] == 2 && vf[1] < 2)){
    Msg::Error("Cannot read MED file older than V2.2");
    return 0;
  }

  std::vector<std::string> meshNames;
  for(int i = 0; i < MEDnMaa(fid); i++){
    char meshName[MED_TAILLE_NOM + 1], meshDesc[MED_TAILLE_DESC + 1];
    med_int spaceDim;
    med_maillage meshType;
#if (MED_MAJOR_NUM == 3)
    med_int meshDim, nStep;
    char dtUnit[MED_SNAME_SIZE + 1];
    char axisName[3 * MED_SNAME_SIZE + 1], axisUnit[3 * MED_SNAME_SIZE + 1];
    med_sorting_type sortingType;
    med_axis_type axisType;
    if(MEDmeshInfo(fid, i + 1, meshName, &spaceDim, &meshDim, &meshType, meshDesc,
                   dtUnit, &sortingType, &nStep, &axisType, axisName, axisUnit) < 0){
#else
    if(MEDmaaInfo(fid, i + 1, meshName, &spaceDim, &meshType, meshDesc) < 0){
#endif
      Msg::Error("Unable to read mesh information");
      return 0;
    }
    meshNames.push_back(meshName);
  }

  if(MEDfermer(fid) < 0){
    Msg::Error("Unable to close file '%s'", (char*)name.c_str());
    return 0;
  }

  int ret = 1;
  for(unsigned int i = 0; i < meshNames.size(); i++){
    // we use the filename as a kind of "partition" indicator, allowing to
    // complete a model part by part (used e.g. in DDM, since MED does not store
    // a partition index)
    GModel *m = findByName(meshNames[i], name);
    if(!m) m = new GModel(meshNames[i]);
    ret = m->readMED(name, i);
    if(!ret) return 0;
  }
  return ret;
}

int GModel::readMED(const std::string &name, int meshIndex)
{
  med_idt fid = MEDouvrir((char*)name.c_str(), MED_LECTURE);
  if(fid < 0){
    Msg::Error("Unable to open file '%s'", name.c_str());
    return 0;
  }

  int numMeshes = MEDnMaa(fid);
  if(meshIndex >= numMeshes){
    Msg::Info("Could not find mesh %d in MED file", meshIndex);
    return 0;
  }

  checkPointMaxNumbers();
  GModel::setCurrent(this); // make sure we increment max nums in this model

  // read mesh info
  char meshName[MED_TAILLE_NOM + 1], meshDesc[MED_TAILLE_DESC + 1];
  med_int spaceDim, nStep = 1;
  med_maillage meshType;
#if (MED_MAJOR_NUM == 3)
  med_int meshDim;
  char dtUnit[MED_SNAME_SIZE + 1];
  char axisName[3 * MED_SNAME_SIZE + 1], axisUnit[3 * MED_SNAME_SIZE + 1];
  med_sorting_type sortingType;
  med_axis_type axisType;
  if(MEDmeshInfo(fid, meshIndex + 1, meshName, &spaceDim, &meshDim, &meshType, meshDesc,
                 dtUnit, &sortingType, &nStep, &axisType, axisName, axisUnit) < 0){
#else
  if(MEDmaaInfo(fid, meshIndex + 1, meshName, &spaceDim, &meshType, meshDesc) < 0){
#endif
    Msg::Error("Unable to read mesh information");
    return 0;
  }

  // FIXME: we should support multi-step MED3 meshes (probably by
  // storing each mesh as a separate model, with a naming convention
  // e.g. meshName_step%d). This way we could also handle multi-mesh
  // time sequences in MED3.
  if(nStep > 1)
    Msg::Warning("Discarding %d last meshes in multi-step MED mesh", nStep - 1);

  setName(meshName);
  setFileName(name);
  if(meshType == MED_NON_STRUCTURE){
    Msg::Info("Reading %d-D unstructured mesh <<%s>>", spaceDim, meshName);
  }
  else{
    Msg::Error("Reading structured MED meshes is not supported");
    return 0;
  }
  med_int vf[3];
  MEDversionLire(fid, &vf[0], &vf[1], &vf[2]);

  // read nodes
#if (MED_MAJOR_NUM == 3)
  med_bool changeOfCoord, geoTransform;
  med_int numNodes = MEDmeshnEntity(fid, meshName, MED_NO_DT, MED_NO_IT, MED_NODE,
                                    MED_NO_GEOTYPE, MED_COORDINATE, MED_NO_CMODE,
                                    &changeOfCoord, &geoTransform);
#else
  med_int numNodes = MEDnEntMaa(fid, meshName, MED_COOR, MED_NOEUD, MED_NONE,
                                MED_NOD);
#endif
  if(numNodes < 0){
    Msg::Error("Could not read number of MED nodes");
    return 0;
  }
  if(numNodes == 0){
    Msg::Error("No nodes in MED mesh");
    return 0;
  }
  std::vector<MVertex*> verts(numNodes);
  std::vector<med_float> coord(spaceDim * numNodes);
#if (MED_MAJOR_NUM == 3)
  if(MEDmeshNodeCoordinateRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE,
                             &coord[0]) < 0){
#else
  std::vector<char> coordName(spaceDim * MED_TAILLE_PNOM + 1);
  std::vector<char> coordUnit(spaceDim * MED_TAILLE_PNOM + 1);
  med_repere rep;
  if(MEDcoordLire(fid, meshName, spaceDim, &coord[0], MED_FULL_INTERLACE,
                  MED_ALL, 0, 0, &rep, &coordName[0], &coordUnit[0]) < 0){
#endif
    Msg::Error("Could not read MED node coordinates");
    return 0;
  }

  std::vector<med_int> nodeTags(numNodes);
#if (MED_MAJOR_NUM == 3)
  if(MEDmeshEntityNumberRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_NODE,
                           MED_NO_GEOTYPE, &nodeTags[0]) < 0)
#else
  if(MEDnumLire(fid, meshName, &nodeTags[0], numNodes, MED_NOEUD, MED_NONE) < 0)
#endif
    nodeTags.clear();

  for(int i = 0; i < numNodes; i++)
    verts[i] = new MVertex(coord[spaceDim * i],
                           (spaceDim > 1) ? coord[spaceDim * i + 1] : 0.,
                           (spaceDim > 2) ? coord[spaceDim * i + 2] : 0.,
                           0, nodeTags.empty() ? 0 : nodeTags[i]);

  // read elements (loop over all possible MSH element types)
  for(int mshType = 0; mshType < MSH_NUM_TYPE; mshType++){
    med_geometrie_element type = msh2medElementType(mshType);
    if(type == MED_NONE) continue;
#if (MED_MAJOR_NUM == 3)
    med_bool changeOfCoord;
    med_bool geoTransform;
    med_int numEle = MEDmeshnEntity(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL,
                                    type, MED_CONNECTIVITY, MED_NODAL, &changeOfCoord,
                                    &geoTransform);
#else
    med_int numEle = MEDnEntMaa(fid, meshName, MED_CONN, MED_MAILLE, type, MED_NOD);
#endif
    if(numEle <= 0) continue;
    int numNodPerEle = type % 100;
    std::vector<med_int> conn(numEle * numNodPerEle);
#if (MED_MAJOR_NUM == 3)
    if(MEDmeshElementConnectivityRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL,
                                    type, MED_NODAL, MED_FULL_INTERLACE, &conn[0]) < 0){
#else
    if(MEDconnLire(fid, meshName, spaceDim, &conn[0], MED_FULL_INTERLACE, 0, MED_ALL,
                   MED_MAILLE, type, MED_NOD) < 0){
#endif
      Msg::Error("Could not read MED elements");
      return 0;
    }
    std::vector<med_int> fam(numEle, 0);
#if (MED_MAJOR_NUM == 3)
    if(MEDmeshEntityFamilyNumberRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL,
                                   type, &fam[0]) < 0){
#else
    if(MEDfamLire(fid, meshName, &fam[0], numEle, MED_MAILLE, type) < 0){
#endif
      Msg::Info("No family number for elements: using 0 as default family number");
    }
    std::vector<med_int> eleTags(numEle);
#if (MED_MAJOR_NUM == 3)
    if(MEDmeshEntityNumberRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL,
                             type, &eleTags[0]) < 0)
#else
    if(MEDnumLire(fid, meshName, &eleTags[0], numEle, MED_MAILLE, type) < 0)
#endif
      eleTags.clear();
    std::map<int, std::vector<MElement*> > elements;
    MElementFactory factory;
    for(int j = 0; j < numEle; j++){
      std::vector<MVertex*> v(numNodPerEle);
      for(int k = 0; k < numNodPerEle; k++)
        v[k] = verts[conn[numNodPerEle * j + med2mshNodeIndex(type, k)] - 1];
      MElement *e = factory.create(mshType, v, eleTags.empty() ? 0 : eleTags[j]);
      if(e) elements[-fam[j]].push_back(e);
    }
    _storeElementsInEntities(elements);
  }
  _associateEntityWithMeshVertices();
  _storeVerticesInEntities(verts);

  // read family info
  med_int numFamilies = MEDnFam(fid, meshName);
  if(numFamilies < 0){
    Msg::Error("Could not read MED families");
    return 0;
  }
  for(int i = 0; i < numFamilies; i++){
#if (MED_MAJOR_NUM == 3)
    med_int numAttrib = (vf[0] == 2) ? MEDnFamily23Attribute(fid, meshName, i + 1) : 0;
    med_int numGroups = MEDnFamilyGroup(fid, meshName, i + 1);
#else
    med_int numAttrib = MEDnAttribut(fid, meshName, i + 1);
    med_int numGroups = MEDnGroupe(fid, meshName, i + 1);
#endif
    if(numAttrib < 0 || numGroups < 0){
      Msg::Error("Could not read MED groups or attributes");
      return 0;
    }
    std::vector<med_int> attribId(numAttrib + 1);
    std::vector<med_int> attribVal(numAttrib + 1);
    std::vector<char> attribDes(MED_TAILLE_DESC * numAttrib + 1);
    std::vector<char> groupNames(MED_TAILLE_LNOM * numGroups + 1);
    char familyName[MED_TAILLE_NOM + 1];
    med_int familyNum;
#if (MED_MAJOR_NUM == 3)
    if(vf[0] == 2){ // MED2 file
      if(MEDfamily23Info(fid, meshName, i + 1, familyName, &attribId[0],
                         &attribVal[0], &attribDes[0], &familyNum,
                         &groupNames[0]) < 0){
        Msg::Error("Could not read info for MED2 family %d", i + 1);
        continue;
      }
    }
    else{
      if(MEDfamilyInfo(fid, meshName, i + 1, familyName, &familyNum,
                       &groupNames[0]) < 0){
        Msg::Error("Could not read info for MED3 family %d", i + 1);
        continue;
      }
    }
#else
    if(MEDfamInfo(fid, meshName, i + 1, familyName, &familyNum, &attribId[0],
                  &attribVal[0], &attribDes[0], &numAttrib, &groupNames[0],
                  &numGroups) < 0){
      Msg::Error("Could not read info for MED family %d", i + 1);
      continue;
    }
#endif
    // family tags are unique (for all dimensions)
    GEntity *ge;
    if((ge = getRegionByTag(-familyNum))){}
    else if((ge = getFaceByTag(-familyNum))){}
    else if((ge = getEdgeByTag(-familyNum))){}
    else ge = getVertexByTag(-familyNum);
    if(ge){
      elementaryNames[std::pair<int, int>(ge->dim(), -familyNum)] = familyName;
      if(numGroups > 0){
        for(int j = 0; j < numGroups; j++){
          char tmp[MED_TAILLE_LNOM + 1];
          strncpy(tmp, &groupNames[j * MED_TAILLE_LNOM], MED_TAILLE_LNOM);
          tmp[MED_TAILLE_LNOM] = '\0';
          // don't use same physical number across dimensions, as e.g. getdp
          // does not support this
          int pnum = setPhysicalName(tmp, ge->dim(), getMaxPhysicalNumber(-1) + 1);
          if(std::find(ge->physicals.begin(), ge->physicals.end(), pnum) ==
             ge->physicals.end())
            ge->physicals.push_back(pnum);
        }
      }
    }
  }

  // check if we need to read some post-processing data later
#if (MED_MAJOR_NUM == 3)
  bool postpro = (MEDnField(fid) > 0) ? true : false;
#else
  bool postpro = (MEDnChamp(fid, 0) > 0) ? true : false;
#endif

  if(MEDfermer(fid) < 0){
    Msg::Error("Unable to close file '%s'", (char*)name.c_str());
    return 0;
  }

  return postpro ? 2 : 1;
}

template<class T>
static void fillElementsMED(med_int family, std::vector<T*> &elements,
                            std::vector<med_int> &conn, std::vector<med_int> &fam,
                            med_geometrie_element &type)
{
  if(elements.empty()) return;
  type = msh2medElementType(elements[0]->getTypeForMSH());
  if(type == MED_NONE){
    Msg::Warning("Unsupported element type in MED format");
    return;
  }
  for(unsigned int i = 0; i < elements.size(); i++){
    elements[i]->setVolumePositive();
    for(int j = 0; j < elements[i]->getNumVertices(); j++)
      conn.push_back(elements[i]->getVertex(med2mshNodeIndex(type, j))->getIndex());
    fam.push_back(family);
  }
}

static void writeElementsMED(med_idt &fid, char *meshName, std::vector<med_int> &conn,
                             std::vector<med_int> &fam, med_geometrie_element type)
{
  if(fam.empty()) return;
#if (MED_MAJOR_NUM == 3)
  if(MEDmeshElementWr(fid, meshName, MED_NO_DT, MED_NO_IT, 0., MED_CELL, type,
                      MED_NODAL, MED_FULL_INTERLACE, (med_int)fam.size(),
                      &conn[0], MED_FALSE, 0, MED_FALSE, 0, MED_TRUE, &fam[0]) < 0)
#else
  if(MEDelementsEcr(fid, meshName, (med_int)3, &conn[0], MED_FULL_INTERLACE,
                    0, MED_FAUX, 0, MED_FAUX, &fam[0], (med_int)fam.size(),
                    MED_MAILLE, type, MED_NOD) < 0)
#endif
    Msg::Error("Could not write MED elements");
}

int GModel::writeMED(const std::string &name, bool saveAll, double scalingFactor)
{
  med_idt fid = MEDouvrir((char*)name.c_str(), MED_CREATION);
  if(fid < 0){
    Msg::Error("Unable to open file '%s'", name.c_str());
    return 0;
  }

  // write header
  if(MEDfichDesEcr(fid, (char*)"MED file generated by Gmsh") < 0){
    Msg::Error("Unable to write MED descriptor");
    return 0;
  }

  char *meshName = (char*)getName().c_str();

  // Gmsh always writes 3D unstructured meshes
#if (MED_MAJOR_NUM == 3)
  char dtUnit[MED_SNAME_SIZE + 1] = "";
  char axisName[3 * MED_SNAME_SIZE + 1] = "";
  char axisUnit[3 * MED_SNAME_SIZE + 1] = "";
  if(MEDmeshCr(fid, meshName, 3, 3, MED_UNSTRUCTURED_MESH, "Mesh created with Gmsh",
               dtUnit, MED_SORT_DTIT, MED_CARTESIAN, axisName, axisUnit) < 0){
#else
  if(MEDmaaCr(fid, meshName, 3, MED_NON_STRUCTURE,
              (char*)"Mesh created with Gmsh") < 0){
#endif
    Msg::Error("Could not create MED mesh");
    return 0;
  }

  // if there are no physicals we save all the elements
  if(noPhysicalGroups()) saveAll = true;

  // index the vertices we save in a continuous sequence (MED
  // connectivity is given in terms of vertex indices)
  indexMeshVertices(saveAll);

  // get a vector containing all the geometrical entities in the
  // model (the ordering of the entities must be the same as the one
  // used during the indexing of the vertices)
  std::vector<GEntity*> entities;
  getEntities(entities);

  std::map<GEntity*, int> families;
  // write the families
  {
    // always create a "0" family, with no groups or attributes
#if (MED_MAJOR_NUM == 3)
    if(MEDfamilyCr(fid, meshName, "F_0", 0, 0, "") < 0)
#else
    if(MEDfamCr(fid, meshName, (char*)"F_0", 0, 0, 0, 0, 0, 0, 0) < 0)
#endif
      Msg::Error("Could not create MED family 0");

    // create one family per elementary entity, with one group per
    // physical entity and no attributes
    for(unsigned int i = 0; i < entities.size(); i++){
      if(saveAll || entities[i]->physicals.size()){
        int num = - ((int)families.size() + 1);
        families[entities[i]] = num;
        std::ostringstream fs;
        fs << entities[i]->dim() << "D_" << entities[i]->tag();
        std::string familyName = "F_" + fs.str();
        std::string groupName;
        for(unsigned j = 0; j < entities[i]->physicals.size(); j++){
          std::string tmp = getPhysicalName
            (entities[i]->dim(), entities[i]->physicals[j]);
          if(tmp.empty()){ // create unique name
            std::ostringstream gs;
            gs << entities[i]->dim() << "D_" << entities[i]->physicals[j];
            groupName += "G_" + gs.str();
          }
          else
            groupName += tmp;
          groupName.resize((j + 1) * MED_TAILLE_LNOM, ' ');
        }
#if (MED_MAJOR_NUM == 3)
        if(MEDfamilyCr(fid, meshName, familyName.c_str(),
                       (med_int)num, (med_int)entities[i]->physicals.size(),
                       groupName.c_str()) < 0)
#else
        if(MEDfamCr(fid, meshName, (char*)familyName.c_str(),
                    (med_int)num, 0, 0, 0, 0, (char*)groupName.c_str(),
                    (med_int)entities[i]->physicals.size()) < 0)
#endif
          Msg::Error("Could not create MED family %d", num);
      }
    }
  }

  // write the nodes
  {
    std::vector<med_float> coord;
    std::vector<med_int> fam;
    for(unsigned int i = 0; i < entities.size(); i++){
      for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++){
        MVertex *v = entities[i]->mesh_vertices[j];
        if(v->getIndex() >= 0){
          coord.push_back(v->x() * scalingFactor);
          coord.push_back(v->y() * scalingFactor);
          coord.push_back(v->z() * scalingFactor);
          fam.push_back(0); // we never create node families
        }
      }
    }
    if(fam.empty()){
      Msg::Error("No nodes to write in MED mesh");
      return 0;
    }
#if (MED_MAJOR_NUM == 3)
    if(MEDmeshNodeWr(fid, meshName, MED_NO_DT, MED_NO_IT, 0., MED_FULL_INTERLACE,
                     (med_int)fam.size(), &coord[0], MED_FALSE, "", MED_FALSE, 0,
                     MED_TRUE, &fam[0]) < 0)
#else
    char coordName[3 * MED_TAILLE_PNOM + 1] =
      "x               y               z               ";
    char coordUnit[3 * MED_TAILLE_PNOM + 1] =
      "unknown         unknown         unknown         ";
    if(MEDnoeudsEcr(fid, meshName, (med_int)3, &coord[0], MED_FULL_INTERLACE,
                    MED_CART, coordName, coordUnit, 0, MED_FAUX, 0, MED_FAUX,
                    &fam[0], (med_int)fam.size()) < 0)
#endif
      Msg::Error("Could not write nodes");
  }

  // write the elements
  {
    { // points
      med_geometrie_element typ = MED_NONE;
      std::vector<med_int> conn, fam;
      for(viter it = firstVertex(); it != lastVertex(); it++)
        if(saveAll || (*it)->physicals.size())
          fillElementsMED(families[*it], (*it)->points, conn, fam, typ);
      writeElementsMED(fid, meshName, conn, fam, typ);
    }
    { // lines
      med_geometrie_element typ = MED_NONE;
      std::vector<med_int> conn, fam;
      for(eiter it = firstEdge(); it != lastEdge(); it++)
        if(saveAll || (*it)->physicals.size())
          fillElementsMED(families[*it], (*it)->lines, conn, fam, typ);
      writeElementsMED(fid, meshName, conn, fam, typ);
    }
    { // triangles
      med_geometrie_element typ = MED_NONE;
      std::vector<med_int> conn, fam;
      for(fiter it = firstFace(); it != lastFace(); it++)
        if(saveAll || (*it)->physicals.size())
          fillElementsMED(families[*it], (*it)->triangles, conn, fam, typ);
      writeElementsMED(fid, meshName, conn, fam, typ);
    }
    { // quads
      med_geometrie_element typ = MED_NONE;
      std::vector<med_int> conn, fam;
      for(fiter it = firstFace(); it != lastFace(); it++)
        if(saveAll || (*it)->physicals.size())
          fillElementsMED(families[*it], (*it)->quadrangles, conn, fam, typ);
      writeElementsMED(fid, meshName, conn, fam, typ);
    }
    { // tets
      med_geometrie_element typ = MED_NONE;
      std::vector<med_int> conn, fam;
      for(riter it = firstRegion(); it != lastRegion(); it++)
        if(saveAll || (*it)->physicals.size())
          fillElementsMED(families[*it], (*it)->tetrahedra, conn, fam, typ);
      writeElementsMED(fid, meshName, conn, fam, typ);
    }
    { // hexas
      med_geometrie_element typ = MED_NONE;
      std::vector<med_int> conn, fam;
      for(riter it = firstRegion(); it != lastRegion(); it++)
        if(saveAll || (*it)->physicals.size())
          fillElementsMED(families[*it], (*it)->hexahedra, conn, fam, typ);
      writeElementsMED(fid, meshName, conn, fam, typ);
    }
    { // prisms
      med_geometrie_element typ = MED_NONE;
      std::vector<med_int> conn, fam;
      for(riter it = firstRegion(); it != lastRegion(); it++)
        if(saveAll || (*it)->physicals.size())
          fillElementsMED(families[*it], (*it)->prisms, conn, fam, typ);
      writeElementsMED(fid, meshName, conn, fam, typ);
    }
    { // pyramids
      med_geometrie_element typ = MED_NONE;
      std::vector<med_int> conn, fam;
      for(riter it = firstRegion(); it != lastRegion(); it++)
        if(saveAll || (*it)->physicals.size())
          fillElementsMED(families[*it], (*it)->pyramids, conn, fam, typ);
      writeElementsMED(fid, meshName, conn, fam, typ);
    }
  }

  if(MEDfermer(fid) < 0){
    Msg::Error("Unable to close file '%s'", (char*)name.c_str());
    return 0;
  }

  return 1;
}

#else

int GModel::readMED(const std::string &name)
{
  Msg::Error("Gmsh must be compiled with MED support to read '%s'",
             name.c_str());
  return 0;
}
Ejemplo n.º 30
0
void AccountingSelector::insertDir(QDir d, QListViewItem *root) {

  QListViewItem* tli = 0;

  // sanity check
  if(!d.exists() || !d.isReadable())
    return;


  // set up filter
  d.setNameFilter("*.rst");
  d.setFilter(QDir::Files);
  d.setSorting(QDir::Name);

  // read the list of files
  const QFileInfoList_qt3 *list = d.entryInfoList_qt3();
  QFileInfoListIterator it( *list );
  QFileInfo *fi;

  // traverse the list and insert into the widget
  while((fi = it.current())) {
    ++it;

    QString samename = fi->fileName();

    QListViewItem *i = findByName(samename);

    // skip this file if already in tree
    if(i)
      continue;

    // check if this is the file we should mark
    QString name = fileNameToName(fi->baseName(true));
    if(root)
      tli = new QListViewItem(root, name);
    else
      tli = new QListViewItem(tl, name);

    tli->setPixmap(0, pmfile);

    // check if this is the item we are searching for
    // (only in "Edit"-mode, not in "New"-mode
    if(!isnewaccount && !edit_s.isEmpty() &&
       (edit_s == QString(fi->filePath()).right(edit_s.length()))) {
      edit_item = tli;
    }
  }

  // set up a filter for the directories
  d.setFilter(QDir::Dirs);
  d.setNameFilter("*");
  const QFileInfoList_qt3 *dlist = d.entryInfoList_qt3();
  QFileInfoListIterator dit(*dlist);

  while((fi = dit.current())) {
    // skip "." and ".." directories
    if(fi->fileName().left(1) != ".") {
      // convert to human-readable name
      QString name = fileNameToName(fi->fileName());

      // if the tree already has an item with this name,
      // skip creation and use this one, otherwise
      // create a new entry
      QListViewItem *i = findByName(name);
      if(!i) {
        QListViewItem* item;

        if(root)
          item = new QListViewItem(root, name);
        else
          item = new QListViewItem(tl, name);

        item->setPixmap(0, pmfolder);

	insertDir(QDir(fi->filePath()), item);
      } else
	insertDir(QDir(fi->filePath()), i);
    }
    ++dit;
  }
}