📄 style_manager.cpp
字号:
} return *style;}const Vector& StyleManager::GetObjectColor(const Molecule *molecule) const{ static const Vector black(0,0,0); const StructureObject *object; if (!molecule || !molecule->GetParentOfType(&object)) return black; return GlobalColors()->Get(Colors::eCycle1, object->id - 1);}bool StyleManager::EditGlobalStyle(wxWindow *parent){ StyleDialog dialog(parent, &globalStyle, structureSet); return (dialog.ShowModal() == wxOK);}CCn3d_style_dictionary * StyleManager::CreateASNStyleDictionary(void) const{ auto_ptr<CCn3d_style_dictionary> dictionary(new CCn3d_style_dictionary()); if (!globalStyle.SaveSettingsToASN(&(dictionary->SetGlobal_style()))) return NULL; if (userStyles.size() > 0) { // create an ordered list of style id's typedef list < int > IntList; IntList keys; StyleMap::const_iterator s, se = userStyles.end(); for (s=userStyles.begin(); s!=se; ++s) keys.push_back(s->first); keys.sort(); // create a new style table entry for each user style IntList::const_iterator i, ie = keys.end(); for (i=keys.begin(); i!=ie; ++i) { CRef < CCn3d_style_table_item > entry(new CCn3d_style_table_item()); entry->SetId().Set(*i); if (!userStyles.find(*i)->second.SaveSettingsToASN(&(entry->SetStyle()))) return NULL; dictionary->SetStyle_table().push_back(entry); } } return dictionary.release();}bool StyleManager::LoadFromASNStyleDictionary(const CCn3d_style_dictionary& styleDictionary){ if (!globalStyle.LoadSettingsFromASN(styleDictionary.GetGlobal_style())) return false; userStyles.clear(); if (styleDictionary.IsSetStyle_table()) { CCn3d_style_dictionary::TStyle_table::const_iterator t, te = styleDictionary.GetStyle_table().end(); for (t=styleDictionary.GetStyle_table().begin(); t!=te; ++t) { int id = (*t)->GetId().Get(); if (userStyles.find(id) != userStyles.end()) { ERRORMSG("repeated style table id in style dictionary"); return false; } else if (!userStyles[id].LoadSettingsFromASN((*t)->GetStyle())) return false; } } return true;}bool StyleManager::EditUserAnnotations(wxWindow *parent){ AnnotateDialog dialog(parent, this, structureSet); dialog.ShowModal(); return false;}void StyleManager::GetUserAnnotations(AnnotationPtrList *annotationList){ annotationList->resize(userAnnotations.size()); AnnotationList::iterator a = userAnnotations.begin(); for (int i=0; i<userAnnotations.size(); ++i) (*annotationList)[i] = &(*(a++));}bool StyleManager::AddUserStyle(int *id, StyleSettings **newStyle){ // create a style with the lowest integer id (above zero) available static const int max = 10000; for (int i=1; i<max; ++i) { if (userStyles.find(i) == userStyles.end()) { *newStyle = &(userStyles[i]); *id = i; structureSet->SetDataChanged(StructureSet::eStyleData); return true; } } return false;}bool StyleManager::RemoveUserStyle(int id){ StyleMap::iterator u = userStyles.find(id); if (u == userStyles.end()) return false; userStyles.erase(u); structureSet->SetDataChanged(StructureSet::eStyleData); return true;}StyleManager::UserAnnotation * StyleManager::AddUserAnnotation(void){ userAnnotations.resize(userAnnotations.size() + 1); structureSet->SetDataChanged(StructureSet::eStyleData); return &(userAnnotations.back());}bool StyleManager::RemoveUserAnnotation(UserAnnotation *annotation){ // remove annotation from displayed list AnnotationPtrList::iterator d, de = userAnnotationsDisplayed.end(); for (d=userAnnotationsDisplayed.begin(); d!=de; ++d) { if (annotation == *d) { userAnnotationsDisplayed.erase(d); GlobalMessenger()->PostRedrawAllStructures(); GlobalMessenger()->PostRedrawAllSequenceViewers(); break; } } // remove annotation from available list AnnotationList::iterator u, ue = userAnnotations.end(); int removedStyleID = -1; for (u=userAnnotations.begin(); u!=ue; ++u) { if (annotation == &(*u)) { removedStyleID = u->styleID; userAnnotations.erase(u); break; } } if (u == ue) return false; // also remove the style if it's not used by any other annotation for (u=userAnnotations.begin(); u!=ue; ++u) if (u->styleID == removedStyleID) break; if (u == ue) RemoveUserStyle(removedStyleID); structureSet->SetDataChanged(StructureSet::eStyleData); return true;}bool StyleManager::DisplayAnnotation(UserAnnotation *annotation, bool display){ // first check to make sure this annotation is known AnnotationList::const_iterator a, ae = userAnnotations.end(); for (a=userAnnotations.begin(); a!=ae; ++a) if (annotation == &(*a)) break; if (a == ae) return false; // then look for it in the list of displayed annotations AnnotationPtrList::iterator d, de = userAnnotationsDisplayed.end(); for (d=userAnnotationsDisplayed.begin(); d!=de; ++d) if (annotation == *d) break; // finally, add or remove it from the displayed annotations bool changed = false; if (display && d == de) { userAnnotationsDisplayed.insert(userAnnotationsDisplayed.begin(), annotation); changed = true; } else if (!display && d != de) { userAnnotationsDisplayed.erase(d); changed = true; } if (changed) { // need to redraw if displayed annotations list has changed GlobalMessenger()->PostRedrawAllStructures(); GlobalMessenger()->PostRedrawAllSequenceViewers(); structureSet->SetDataChanged(StructureSet::eStyleData); } return true;}bool StyleManager::ReprioritizeDisplayOrder(UserAnnotation *annotation, bool moveUp){ // look for the annotation in the list of displayed annotations int d; for (d=0; d<userAnnotationsDisplayed.size(); ++d) if (annotation == userAnnotationsDisplayed[d]) break; if (d == userAnnotationsDisplayed.size()) return false; bool changed = false; if (moveUp && d > 0) { userAnnotationsDisplayed[d] = userAnnotationsDisplayed[d - 1]; userAnnotationsDisplayed[d - 1] = annotation; changed = true; } else if (!moveUp && d < userAnnotationsDisplayed.size() - 1) { userAnnotationsDisplayed[d] = userAnnotationsDisplayed[d + 1]; userAnnotationsDisplayed[d + 1] = annotation; changed = true; } if (changed) { // need to redraw if displayed annotations list has changed GlobalMessenger()->PostRedrawAllStructures(); GlobalMessenger()->PostRedrawAllSequenceViewers(); structureSet->SetDataChanged(StructureSet::eStyleData); } return true;}static bool CreateObjectLocation( CCn3d_user_annotation::TResidues *residuesASN, const StyleManager::ResidueMap& residueMap){ residuesASN->clear(); StyleManager::ResidueMap::const_iterator r, re = residueMap.end(); for (r=residueMap.begin(); r!=re; ++r) { // find an existing object location that matches this MMDB ID CCn3d_user_annotation::TResidues::iterator l, le = residuesASN->end(); for (l=residuesASN->begin(); l!=le; ++l) if ((*l)->GetStructure_id().GetMmdb_id().Get() == r->first->mmdbID) break; // if necessary, create new object location, with Biostruc-id from MMDB ID if (l == le) { CRef < CCn3d_object_location > loc(new CCn3d_object_location()); if (r->first->mmdbID != MoleculeIdentifier::VALUE_NOT_SET) { CMmdb_id *mmdbID = new CMmdb_id(); mmdbID->Set(r->first->mmdbID); loc->SetStructure_id().SetMmdb_id(*mmdbID); } else { ERRORMSG("CreateObjectLocation() - MoleculeIdentifier must (currently) have MMDB ID"); return false; } residuesASN->push_back(loc); l = residuesASN->end(); --l; // set iterator to the new object location } // set molecule location CRef < CCn3d_molecule_location > molecule(new CCn3d_molecule_location()); molecule->SetMolecule_id().Set(r->first->moleculeID); (*l)->SetResidues().push_back(molecule); // check if covers whole molecule; if so, leave 'residues' field of Cn3d_molecule_location blank int i; for (i=0; i<r->second.size(); ++i) if (!r->second[i]) break; // else break list down into individual contiguous residue ranges if (i != r->second.size()) { int first = 0, last = 0; while (first < r->second.size()) { // find first included residue while (first < r->second.size() && !r->second[first]) ++first; if (first >= r->second.size()) break; // find last in contiguous stretch of included residues last = first; while (last + 1 < r->second.size() && r->second[last + 1]) ++last; CRef < CCn3d_residue_range > range(new CCn3d_residue_range()); range->SetFrom().Set(first + 1); // assume moleculeID = index + 1 range->SetTo().Set(last + 1); molecule->SetResidues().push_back(range); first = last + 2; } if (molecule->GetResidues().size() == 0) { ERRORMSG("CreateObjectLocation() - no residue ranges found"); return false; } } } return true;}bool StyleManager::SaveToASNUserAnnotations(ncbi::objects::CCn3d_user_annotations *annotations) const{ if (!annotations) return false; annotations->ResetAnnotations(); if (userAnnotations.size() == 0) return true; AnnotationList::const_iterator a, ae = userAnnotations.end(); AnnotationPtrList::const_iterator d, de = userAnnotationsDisplayed.end(); for (a=userAnnotations.begin(); a!=ae; ++a) { // fill out individual annotations CRef < CCn3d_user_annotation > annotation(new CCn3d_user_annotation()); annotation->SetName(a->name); annotation->SetDescription(a->description); annotation->SetStyle_id().Set(a->styleID); // is this annotation on? check displayed annotations list for (d=userAnnotationsDisplayed.begin(); d!=de; ++d) if (*d == &(*a)) break; annotation->SetIs_on(d != de); // fill out residues list if (!CreateObjectLocation(&(annotation->SetResidues()), a->residues)) { ERRORMSG("StyleManager::CreateASNUserAnnotations() - error creating object location"); return false; } annotations->SetAnnotations().push_back(annotation); } return true;}static bool ExtractObjectLocation( StyleManager::ResidueMap *residueMap, const CCn3d_user_annotation::TResidues& residuesASN){ CCn3d_user_annotation::TResidues::const_iterator o, oe = residuesASN.end(); for (o=residuesASN.begin(); o!=oe; ++o) { int mmdbID; if ((*o)->GetStructure_id().IsM
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -