// ExtendToLength ---------------------------- // --------------- void plAGAnim::ExtendToLength(float length) { if (length > GetEnd()) SetEnd(length); }
/********************************************************************** * CTextRun::Speak() * *-------------------* * Description: * Uses *plStart and *plEnd to find the nearest start and * endpoints for speaking (to the nearest word). * Returns these values in plStart and plEnd. * Speaks the text associated with this CTextRun from *plStart * to *plEnd. * * If *plStart is not within the range, then * start at the beginning. If lEnd is not within range, then * end at the end. * * Return: * S_OK * E_POINTER * Return value of CTextRun::Speak() **********************************************************************/ HRESULT CTextRun::Speak( ISpVoice &rVoice, long *plStart, long *plEnd ) { if ( !plStart || !plEnd ) { return E_POINTER; } _ASSERTE( m_cpTextRange ); if ( !m_cpTextRange ) { return E_UNEXPECTED; } // Save the old range long lOldStart = GetStart(); long lOldEnd = GetEnd(); // Out of range start or end means we start speaking from the start // or end (resp.) of the text range. if ( WithinRange( *plStart ) ) { // The start needs to be moved SetStart( *plStart ); } else { *plStart = GetStart(); } if ( WithinRange( *plEnd ) ) { // The end needs to be moved SetEnd( *plEnd ); } else { *plEnd = GetEnd(); } // Expand to include whole words m_cpTextRange->Expand( tomWord, NULL ); // Get the new start and end so that we can pass them back m_cpTextRange->GetStart( plStart ); m_cpTextRange->GetEnd( plEnd ); // We should never speak past the end of this run, even if expanding to include // whole words caused extra text to be included // (e.g. if you typed "This is a sentence" and dictated some text that // consumed leading spaces right afterwards) *plStart = __max( *plStart, lOldStart ); *plEnd = __min( *plEnd, lOldEnd ); SetStart( *plStart ); SetEnd( *plEnd ); // Pass to the CTextRun::Speak() that speaks an entire run HRESULT hr = Speak( rVoice ); // Restore the old range limits SetStart( lOldStart ); SetEnd( lOldEnd ); return hr; } /* CTextRun::Speak */
/********************************************************************* * CTextRun::IsDegenerate * *------------------------* * Description: * Determines whether "this" has a degenerate range associated * with it. * Return: * true iff start == end **********************************************************************/ bool CTextRun::IsDegenerate() { return ( GetStart() == GetEnd() ); } /* CTextRun::IsDegenerate */
/* Extend the buffer over the content of the other buffer, assuming it is * adjacent. */ void Extend(Buffer aOther) { MOZ_ASSERT(aOther.mBuf == GetEnd()); mLength += aOther.mLength; }
/********************************************************************** * CTextRun::Concatenate * *-----------------------* * Description: * If possible, concatenates pNext (pPrev if fConcatAfter is false) * onto the end of this. * Another CTextRun can always be concatenated on, unless it * contains dictation. * * Return: * E_NOMERGE if could not be merged (because pTextRun is dictation) * E_FULLMERGE **********************************************************************/ MERGERESULT CTextRun::Concatenate( CTextRun *pTextRun, bool fConcatAfter ) { if ( !pTextRun || !m_cpTextRange ) { return E_NOMERGE; } // Check for compatibility: In this case, neither mergee can be // a dict run if ( IsDict() || pTextRun->IsDict() ) { return E_NOMERGE; } // lNewBound will be the new end (resp. start) of the run, if the // concatenation is successful long lNewBound; // Concatenation is possible iff one run ends exactly where the other // begins. // If concatenation is possible, do it. if ( fConcatAfter ) { // Will be concatenating pTextRun onto the end of this if ( GetEnd() != pTextRun->GetStart() ) { // They are not consecutive runs return E_NOMERGE; } // lNewBound will be the new end of the run, if the // concatenation is successful lNewBound = pTextRun->GetEnd(); // Swallow up pTextRun by setting our end to its end SetEnd( lNewBound ); // Make pTextRun degenerate pTextRun->SetStart( lNewBound ); } else { // Will be concatenating pTextRun onto the beginning of this if ( GetStart() != pTextRun->GetEnd() ) { return E_NOMERGE; } // lNewBound will be the new start of the run, if the // concatenation is successful lNewBound = pTextRun->GetStart(); // Swallow up pTextRun by setting our start to its start SetStart( lNewBound ); // Make pTextRun degenerate pTextRun->SetEnd( lNewBound ); } return E_FULLMERGE; } /* CTextRun::Concatenate */
// Tokenize //------------------------------------------------------------------------------ void AString::Tokenize( Array< AString > & tokens, char splitChar ) const { Array< const char * > tokenStarts; Array< const char * > tokenEnds; const char * pos = Get(); const char * end = GetEnd(); bool lookingForStart = true; char quoteChar = 0; while ( pos < end ) { if ( lookingForStart ) { if ( *pos == splitChar ) { ++pos; continue; } // found the start of a new token tokenStarts.Append( pos ); lookingForStart = false; } // hit a quote? char c = *pos; if ( ( c == '"' ) || ( c == '\'' ) ) { if ( quoteChar == 0 ) { // opening quote quoteChar = c; } else if ( quoteChar == c ) { // closing quote quoteChar = 0; } else { // quote of the 'other' type - consider as part of token } } else if ( c == splitChar ) { if ( quoteChar == 0 ) { tokenEnds.Append( pos ); lookingForStart = true; } else { // space inside quoted token - consider as part of token } } else { // normal character part of token } ++pos; } ASSERT( ( tokenStarts.GetSize() == tokenEnds.GetSize() ) || ( tokenStarts.GetSize() == ( tokenEnds.GetSize() + 1 ) ) ); if ( tokenStarts.GetSize() > tokenEnds.GetSize() ) { tokenEnds.Append( pos ); } ASSERT( tokenStarts.GetSize() == tokenEnds.GetSize() ); // pre-size output to avoid reallocations tokens.Clear(); const size_t numTokens( tokenStarts.GetSize() ); if ( tokens.GetCapacity() < numTokens ) { tokens.SetCapacity( numTokens ); } tokens.SetSize( numTokens ); // copy tokens for ( size_t i=0; i<numTokens; ++i ) { tokens[ i ].Assign( tokenStarts[ i ], tokenEnds[ i ] ); } }
/*! * Tells if the range contains all addresses in another range. * * @param[in] range Range to test. * * @return TRUE if range contains \a range. */ bool Contains(const RANGE &range) const { return (Contains(range.m_base) && !range.Contains(GetEnd())); }
/*! * Aligns the starting and ending addresses of the range. Afterwards, the * original range is contained by the new one, and the start and end are aligned. * * @param[in] alignment Desired alignement (bytes). */ void AlignEndpoints(size_t alignment) { ADDRTYPE end = RoundUp(GetEnd(), alignment); _base = RoundDown(_base, alignment); _size = end - _base; }
bool LIB_EDIT_FRAME::HandleBlockEnd( wxDC* aDC ) { int ItemCount = 0; bool nextCmd = false; BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate; wxPoint pt; auto panel =static_cast<SCH_DRAW_PANEL*>(m_canvas); auto view = panel->GetView(); auto area = view->GetSelectionArea(); auto start = area->GetOrigin(); auto end = area->GetEnd(); block->SetOrigin( wxPoint( start.x, start.y ) ); block->SetEnd( wxPoint( end.x, end.y ) ); view->ShowSelectionArea( false ); view->ClearHiddenFlags(); if( block->GetCount() ) { BLOCK_STATE_T state = block->GetState(); BLOCK_COMMAND_T command = block->GetCommand(); m_canvas->CallEndMouseCapture( aDC ); block->SetState( state ); block->SetCommand( command ); m_canvas->SetMouseCapture( DrawAndSizingBlockOutlines, AbortBlockCurrentCommand ); if( block->GetCommand() != BLOCK_ABORT && block->GetCommand() != BLOCK_DUPLICATE && block->GetCommand() != BLOCK_COPY && block->GetCommand() != BLOCK_CUT && block->GetCommand() != BLOCK_DELETE ) { SetCrossHairPosition( block->GetEnd() ); m_canvas->MoveCursorToCrossHair(); } } if( m_canvas->IsMouseCaptured() ) { switch( block->GetCommand() ) { case BLOCK_IDLE: DisplayError( this, wxT( "Error in HandleBlockPLace" ) ); break; case BLOCK_DRAG: // Drag case BLOCK_DRAG_ITEM: case BLOCK_MOVE: // Move case BLOCK_DUPLICATE: // Duplicate if( GetCurPart() ) ItemCount = BlockSelectItems( GetCurPart(), block, m_unit, m_convert, m_syncPinEdit ); if( ItemCount ) { nextCmd = true; block->SetState( STATE_BLOCK_MOVE ); if( block->GetCommand() == BLOCK_DUPLICATE ) { if( block->AppendUndo() ) ; // UR_LIBEDIT saves entire state, so no need to append anything more else { SaveCopyInUndoList( GetCurPart(), UR_LIBEDIT ); block->SetAppendUndo(); } BlockCopySelectedItems( pt, GetCurPart(), block ); block->SetLastCursorPosition( GetCrossHairPosition( true ) ); } m_canvas->SetMouseCaptureCallback( DrawMovingBlockOutlines ); m_canvas->CallMouseCapture( aDC, wxDefaultPosition, false ); } else { m_canvas->CallMouseCapture( aDC, wxDefaultPosition, false ); m_canvas->SetMouseCapture( NULL, NULL ); } break; case BLOCK_COPY: // Save a copy of items in the clipboard buffer case BLOCK_CUT: if( GetCurPart() ) ItemCount = BlockSelectItems( GetCurPart(), block, m_unit, m_convert, m_syncPinEdit ); if( ItemCount ) { copySelectedItems(); auto cmd = block->GetCommand(); if( cmd == BLOCK_COPY ) { BlockClearSelectedItems( GetCurPart(), block ); block->ClearItemsList(); } else if( cmd == BLOCK_CUT ) { if( block->AppendUndo() ) ; // UR_LIBEDIT saves entire state, so no need to append anything more else { SaveCopyInUndoList( GetCurPart(), UR_LIBEDIT ); block->SetAppendUndo(); } BlockDeleteSelectedItems( GetCurPart(), block ); RebuildView(); GetCanvas()->Refresh(); OnModify(); } } break; case BLOCK_DELETE: // Delete if( GetCurPart() ) ItemCount = BlockSelectItems( GetCurPart(), block, m_unit, m_convert, m_syncPinEdit ); if( block->AppendUndo() ) ; // UR_LIBEDIT saves entire state, so no need to append anything more else if( ItemCount ) { SaveCopyInUndoList( GetCurPart(), UR_LIBEDIT ); block->SetAppendUndo(); } if( GetCurPart() ) { BlockDeleteSelectedItems( GetCurPart(), block ); RebuildView(); GetCanvas()->Refresh(); OnModify(); } break; case BLOCK_PASTE: case BLOCK_ROTATE: case BLOCK_MIRROR_X: case BLOCK_MIRROR_Y: case BLOCK_FLIP: wxFAIL; // should not happen break; case BLOCK_ZOOM: // Window Zoom Window_Zoom( *block ); break; case BLOCK_ABORT: break; case BLOCK_SELECT_ITEMS_ONLY: break; case BLOCK_PRESELECT_MOVE: // not used in LibEdit case BLOCK_DUPLICATE_AND_INCREMENT: // not used in Eeschema case BLOCK_MOVE_EXACT: // not used in Eeschema break; } } if( block->GetCommand() == BLOCK_ABORT ) { GetScreen()->ClearDrawingState(); } if( !nextCmd ) { if( block->GetCommand() != BLOCK_SELECT_ITEMS_ONLY && GetCurPart() ) BlockClearSelectedItems( GetCurPart(), block ); GetScreen()->ClearBlockCommand(); GetScreen()->SetCurItem( NULL ); m_canvas->EndMouseCapture( GetToolId(), GetGalCanvas()->GetCurrentCursor(), wxEmptyString, false ); } view->ShowSelectionArea( false ); view->ShowPreview( nextCmd ); return nextCmd; }
NodeList_t& AStar::FindPath() { Reset(); FoundPath = false; //Msg("Reset Variables: %i, %i, %i\n", Path.Count(), Opened.Count(), Closed.Count()); if(GetStart() == GetEnd()) { //Msg("Start Is End\n"); return Path; } // 1) Add the starting node to the open list. AddOpenedNode(Start); Start->SetStatus(NULL, 0, 0, 0); float CurrentScoreG; float ScoreF, ScoreG, ScoreH; NodeList_t Links; AStarNode *Current = NULL, *LastNode = NULL, *Link = NULL; //Msg("Added Node\n"); // 2) Repeat the following: while(true) { // a) Look for the lowest F cost square on the open list. We refer to this as the current square. Current = FindLowestF(); if(Current != NULL) { LastNode = Current; if(Current->GetPos() == End->GetPos()) { FoundPath = true; break; } else { CurrentScoreG = Current->GetScoreG(); // b) Switch it to the closed list. AddClosedNode(Current); // c) For each of the nodes linked to this node... Links = Current->GetLinks(); ScoreH = HeuristicDistance(Current->GetPos(), End->GetPos()); //Msg("Found Lowest F: %i | %f, %f, %f\n", Links.Count(), Current->GetPos().x, Current->GetPos().y, Current->GetPos().z); for(int i = 0; i < Links.Count(); i++) { Link = Links[i]; if(Link != NULL) { // If it is not walkable or if it is on the closed list, ignore it. if(!Link->IsClosed()) { // If it isn’t on the open list, add it to the open list. Make the current node the parent of this node. Record the F, G, and H costs of the node. if(!Link->IsOpened()) { //Msg("SetStatus\n"); AddOpenedNode(Link); ScoreG = CurrentScoreG + HeuristicDistance(Current->GetPos(), Link->GetPos()); ScoreF = ScoreG + ScoreH; Link->SetStatus(Current, ScoreF, ScoreG, ScoreH); } //if(Link->Opened()) Always true? //{ if(CurrentScoreG > ScoreG) { Link->SetParent(Current); //Msg("Set Parent\n"); } else { //Msg("%f | %f\n", CurrentScoreG, ScoreG); } //} } } } } } else { //Msg("Failed to find Lowest F\n"); break; } } return CalcPath(LastNode); }