plugin_utils.cpp
来自「ncbi源码」· C++ 代码 · 共 1,523 行 · 第 1/4 页
CPP
1,523 行
break; case CPluginValueConstraint::e_Seq_length_range: // constrain a set of sequences such that their lengths are at // least some bound {{ TSeqPos min_len = NStr::StringToInt(cons.GetSeq_length_range().GetLower()); TSeqPos max_len = NStr::StringToInt(cons.GetSeq_length_range().GetUpper()); CObjConverter::TObjList bioseqs; CObjectConverter::Convert(scope, obj, CBioseq::GetTypeInfo(), bioseqs); ITERATE(CObjConverter::TObjList, iter, bioseqs) { const CBioseq* bioseq = dynamic_cast<const CBioseq*>(iter->GetPointer()); if ( !bioseq ) { return false; } if (bioseq->GetInst().GetLength() < min_len || bioseq->GetInst().GetLength() > max_len) { return false; } } }} break; case CPluginValueConstraint::e_Seq_length_same: _TRACE("x_CheckObjectConstraint(): failed: " "seq-inst.length: same length constraint not implemented"); break; // // constraints for seq-entry types // case CPluginValueConstraint::e_Entry_type: // constrain a set of values such that their molecule types are all // the same {{ CObjConverter::TObjList entries; CObjectConverter::Convert(scope, obj, CSeq_entry::GetTypeInfo(), entries); ITERATE(CObjConverter::TObjList, iter, entries) { const CSeq_entry* entry= dynamic_cast<const CSeq_entry*>(iter->GetPointer()); if ( !entry ) { return false; } if ( !entry->IsSet() || !entry->GetSet().IsSetClass() || !entry->GetSet().GetClass() == cons.GetEntry_type()) { return false; } } }} break; // // constraints for seq-annot types // case CPluginValueConstraint::e_Annot_type: // constrain the sequence representation to be of a certain type {{ CObjConverter::TObjList annots; CObjectConverter::Convert(scope, obj, CSeq_annot::GetTypeInfo(), annots); ITERATE(CObjConverter::TObjList, iter, annots) { const CSeq_annot* annot= dynamic_cast<const CSeq_annot*>(iter->GetPointer()); if ( !annot ) { return false; } if (annot->GetData().Which() != cons.GetAnnot_type()) { return false; } } }} break; // // constraints for seq-feat types // case CPluginValueConstraint::e_Feat_type: // constrain the sequence representation to be of a certain type {{ CObjConverter::TObjList feats; CObjectConverter::Convert(scope, obj, CSeq_feat::GetTypeInfo(), feats); ITERATE(CObjConverter::TObjList, iter, feats) { const CSeq_feat* feat= dynamic_cast<const CSeq_feat*>(iter->GetPointer()); if ( !feat ) { return false; } if (std::find(cons.GetFeat_type().begin(), cons.GetFeat_type().end(), feat->GetData().Which()) == cons.GetFeat_type().end()) { return false; } } }} break; // // constraints for seq-feat subtypes // case CPluginValueConstraint::e_Feat_subtype: // constrain the sequence representation to be of a certain type {{ CObjConverter::TObjList feats; CObjectConverter::Convert(scope, obj, CSeq_feat::GetTypeInfo(), feats); ITERATE(CObjConverter::TObjList, iter, feats) { const CSeq_feat* feat= dynamic_cast<const CSeq_feat*>(iter->GetPointer()); if ( !feat ) { return false; } string label; feature::GetLabel(*feat, &label, feature::eBoth, &scope); if (std::find(cons.GetFeat_subtype().begin(), cons.GetFeat_subtype().end(), feat->GetData().GetSubtype()) == cons.GetFeat_subtype().end()) { return false; } } }} break; // // constraints for seq-feats that have products set // case CPluginValueConstraint::e_Feat_has_product: // constrain the sequence representation to be of a certain type {{ CObjConverter::TObjList feats; CObjectConverter::Convert(scope, obj, CSeq_feat::GetTypeInfo(), feats); ITERATE(CObjConverter::TObjList, iter, feats) { const CSeq_feat* feat= dynamic_cast<const CSeq_feat*>(iter->GetPointer()); if ( !feat ) { return false; } if ( !feat->IsSetProduct() ) { return false; } } }} break; default: LOG_POST(Error << "CPluginArg::CheckConstraint():" " unhandled constraint type: " << (int)cons.Which()); return false; break; } } return true;}//// utility function to convert a set of selections into a set of arguments//int CPluginUtils::FillArgs(CPluginArgSet& args, const IDocument& doc){ TConstScopedObjects sels; sels.push_back(SConstScopedObject(doc, doc.GetScope())); return FillArgs(args, sels);}int CPluginUtils::FillArgs(CPluginArgSet& args, const CPluginArg::TData::TArray& objs){ // step 1: clear any object-based arguments NON_CONST_ITERATE (CPluginArgSet::Tdata, iter, args.Set()) { CPluginArg& arg = **iter; arg.ClearObjects(); } CSelectionBuffer buffer; ITERATE (CPluginArg::TData::TArray, iter, objs) { const CPluginValue& val = **iter; if ( !val.GetObject() ) { continue; } if ( val.IsObject() ) { const CSerialObject* obj = dynamic_cast<const CSerialObject*>(val.GetObject()); IDocument* doc = const_cast<IDocument*>( dynamic_cast<const IDocument*>(val.GetDocument())); if (obj && doc) { buffer.AddSelection(doc, *obj); } } else if ( val.IsDocument() ) { IDocument* doc = const_cast<IDocument*>( dynamic_cast<const IDocument*>(val.GetObject())); if (doc) { buffer.AddSelection(doc); } } } return FillArgs(args, buffer.DecomposeToPairs());}int CPluginUtils::FillArgs(CPluginArgSet& args, const TConstScopedObjects& sels){ // easy out: no arguments to fill if (args.Get().size() == 0) { return 0; } // we plan to handle one case automatically: the set of arguments has // one argument that takes a data model object. Other cases are left // to the user to clarify because these are too complex to guess int visible_args = 0; int obj_args = 0; CRef<CPluginArg> arg_to_fill; NON_CONST_ITERATE (CPluginArgSet::Tdata, iter, args.Set()) { CPluginArg& arg = **iter; if (arg.IsSetHidden() && arg.GetHidden()) { continue; } ++visible_args; CPluginArg::EType type = arg.GetType(); if (type == CPluginArg::eObject || type == CPluginArg::eDocument) { ++obj_args; // clear object argument arg.ClearObjects(); arg_to_fill.Reset(&arg); } } // make sure we actually can address this argument if ( obj_args > 1 || !arg_to_fill ) { return visible_args; } // now, convert as many objects as possible into the requested format // here we plan to support automatic assignments to data model objects // only; CObject assignments can be made for these, but this must be // done under user direction switch (arg_to_fill->GetData().Which()) { case CPluginArg::TData::e_Single: // // make sure we have exactly one selection // if (sels.size() == 1) { const string& target_type = arg_to_fill->GetObjectSubtype(); SConstScopedObject cso = sels.front(); CScope& scope = *cso.scope; IDocument* doc = CDocManager::GetDocumentFromScope(scope); if ( !doc ) { break; } CObjConverter::TObjList obj_list; CObjectConverter::Convert(scope, *cso.object, target_type, obj_list); if (obj_list.size() != 1) { break; } arg_to_fill->SetObject(*doc, *obj_list.front()); if (CPluginUtils::CheckConstraints(*arg_to_fill)) { return visible_args - 1; } } break; case CPluginArg::TData::e_Array: {{ // make sure we preserve existing values CPluginArg::TValues value_list; arg_to_fill->AsList(value_list); // we can assign many objects // first, we do a one-to-many conversion, based on the target type const string& target_type = arg_to_fill->GetObjectSubtype(); // now, iterate our selections and convert as necessary ITERATE (TConstScopedObjects, iter, sels) { SConstScopedObject cso = sels.front(); CScope& scope = *cso.scope; IDocument* doc = CDocManager::GetDocumentFromScope(scope); if ( !doc ) { continue; } CObjectConverter::TObjList obj_list; CObjectConverter::Convert(scope, *iter->object, target_type, obj_list); ITERATE(CObjectConverter::TObjList, obj_iter, obj_list) { CRef<CPluginValue> value(new CPluginValue()); value->SetObject(*doc, **obj_iter); value_list.push_back(value); } } // make sure all of our arguments are valid // we do this such that any unfilled argument will be passed on // if we added nothing to this argument, then our size is 1 if (value_list.size() > 1) { CPluginArg::TValues::iterator iter = value_list.begin(); CPluginArg::TValues::iterator end_iter = value_list.end(); for ( ; iter != end_iter; ) { const CPluginValue& value = **iter; if ( !IsValid(value) ) { iter = value_list.erase(iter); } else { ++iter; } } } arg_to_fill->SetList(value_list); if (CPluginUtils::CheckConstraints(*arg_to_fill)) { return visible_args - 1; } }} break; default: break; } return visible_args;}// this function performs a similar task to FillArgs(); however, instead of// actually filling the set of arguments automatically, it returns true if any// of the selections indicated *can* fit. The primary use of this is to// determine if a set of plugins could accept some of the selectionsbool CPluginUtils::CanFitArgs(const CPluginArgSet& args, const IDocument& doc, CConvertCache* cache){ TConstScopedObjects sels; sels.push_back(SConstScopedObject(doc, doc.GetScope())); return CanFitArgs(args, sels, cache);}bool CPluginUtils::CanFitArgs(const CPluginArgSet& args, const CSelectionBuffer& sels, CConvertCache* cache){ return CanFitArgs(args, sels.DecomposeToPairs(), cache);}bool CPluginUtils::CanFitArgs(const CPluginArgSet& args, const TConstScopedObjects& sels, CConvertCache* cache){ // easy out: no arguments to fill // we're always valid here if (args.Get().size() == 0) { return true; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?